Moving decimal places over in a double

后端 未结 9 1135
别跟我提以往
别跟我提以往 2020-11-22 16:18

So I have a double set to equal 1234, I want to move a decimal place over to make it 12.34

So to do this I multiply .1 to 1234 two times, kinda like this

<         


        
9条回答
  •  天命终不由人
    2020-11-22 17:06

    No, as Java floating point types (indeed all floating point types) are a trade-off between size and precision. While they're very useful for a lot of tasks, if you need arbitrary precision, you should use BigDecimal.

提交回复
热议问题