I want to know how to round a floating-point number to a machine floating number(for example double). The number "0.01111116" cannot be represented by machine floating point, in some rounding mode, this number should be represented as "0.011111159999999995" with some precision loss. But I don't know how to finish this in Java? So I want to know the API to set the rounding mode to get the exact representation of machine floating-point number in Java. Thanks!
The Java specification does not provide any means to control the floating-point rounding mode. Round-to-nearest is used.
It is not generally possible to arrange for floating-point arithmetic to produce mathematically exact results, so software must be designed to tolerate and adjust for errors or, in very special cases, to get exact results by using extra care.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With