import java.math.*;
class Moqueet {
public static void main(String [] args){
double a, b, c;
BigDecimal bg1, bg2;
a = 1;
b = 10000;
c = a / b;
bg1 = new BigDecimal(c);
MathContext mc = new MathContext(10);
bg2 = bg1.round(mc);
System.out.println(bg1);
}
}
当我尝试这个时,我得到如下输出:
0.000100000000000000004792173602385929598312941379845142364501953125
我希望我的出局仅为0.0001
。我怎么能得到这个?
答案 0 :(得分:0)
bg1 = bg1.setScale(4, RoundingMode.FLOOR);