DecimalFormat and Double.valueOf()

后端 未结 10 1281
鱼传尺愫
鱼传尺愫 2020-12-24 15:22

I\'m trying to get rid of unnecessary symbols after decimal seperator of my double value. I\'m doing it this way:

DecimalFormat format = new DecimalFormat(\"         


        
10条回答
  •  佛祖请我去吃肉
    2020-12-24 16:06

    By

    get rid of unnecessary symbols after decimal seperator of my double value

    do you actually mean you want to round to e.g. the 5th decimal? Then just use

    value = Math.round(value*1e5)/1e5;
    

    (of course you can also Math.floor(value*1e5)/1e5 if you really want the other digits cut off)

提交回复
热议问题