How do I truncate the significand of a floating point number to an arbitrary precision in Java? [duplicate]
问题 This question already has answers here : Efficient way to round double precision numbers to a lower precision given in number of bits (2 answers) Closed last year . I would like to introduce some artificial precision loss into two numbers being compared to smooth out minor rounding errors so that I don't have to use the Math.abs(x - y) < eps idiom in every comparison involving x and y . Essentially, I want something that behaves similarly to down-casting a double to a float and then up