Max value can stored in Java float with two digit precision (2 digit accuracy)?

前端 未结 4 937
情深已故
情深已故 2021-01-27 17:55

How I could find max two decimal precision vale that can be stored in float ?

From my understanding, In 32 bit float we have 24(23+1) for storing the number excluding ex

相关标签:
4条回答
  • 2021-01-27 18:26

    2^24 is the largest integer you can store accurately. The largest two decimal places value you can store without loss of precision. 2^24/100.

    Note: even 0.1 & 0.01 cannot be stored accurately but with rounding you can get this value without error. So taking the question literally, the largest value is 0.00. ;)

    The largest value with two digits of precision is close to Float.MAX_VALUE, but I don't think that is what you mean.

    0 讨论(0)
  • 2021-01-27 18:26

    If you simply want to store numbers with exactly two decimal digits after the point, store 100 times the number as an integer (or long, depending on how big your numbers get), and add the point (or comma) on formatting (remove on parsing).

    This is much easier to control.

    0 讨论(0)
  • 2021-01-27 18:34

    Information on the IEEE 754 single precision binary floating-point format can be found on wikipedia

    I think there is no possibility to find such a number. You are talking about a number with two decimal digits in base 10, however you want to store this number as binary value.

    While you are perfectly able to store the exact value of 1.00 in a 32-bit-float you won't be able to store 0.99.

    0 讨论(0)
  • 2021-01-27 18:46

    You cannot specify the precision in a float value. If you limit yourself to 2 decimal places, you don't get more space for something else in return.

    0 讨论(0)
提交回复
热议问题