The code:
import java.math.*;
public class x
{
public static void main(String[] args)
{
BigDecimal a = new BigDecimal(0.1);
BigDecimal b = new BigDecimal(0.7);
System.out.println(a);
System.out.println(b);
}
}
Output:
0.1000000000000000055511151231257827021181583404541015625
0.6999999999999999555910790149937383830547332763671875
This is good because it allows me to find doublewhich is closest to the given value. But as for 0.1, the value is greater, and the value is 0.7less than the real value.
How can I get both values (nearest closest and closest) for any decimal?
Suppose I start with BigDecimal, and then convert it to double, and then back to decimal. I will get more or less. How could I get another?
source
share