3 回答

TA貢獻(xiàn)1784條經(jīng)驗 獲得超9個贊
import java.math.BigDecimal;BigDecimal premium = BigDecimal.valueOf("1586.6");BigDecimal netToCompany = BigDecimal.valueOf("708.75"); BigDecimal commission = premium.subtract(netToCompany);System.out.println(commission + " = " + premium + " - " + netToCompany);
877.85 = 1586.6 - 708.75

TA貢獻(xiàn)1825條經(jīng)驗 獲得超4個贊
java.math.BigDecimal
.
BigDecimal
BigDecimal
BigDecimal(double)
BigDecimal.valueOf(double)
double
BigDecimal
String
BigDecimal
.
BigDecimal
double value = 0.585; System.out.println(new BigDecimal(value)); System.out.println(BigDecimal.valueOf(value));
0.58499999999999996447286321199499070644378662109375 0.585

TA貢獻(xiàn)1946條經(jīng)驗 獲得超4個贊
double d = 0;for (int i = 1; i <= 10; i++) { d += 0.1;}System.out.println(d); // prints 0.9999999999999999 not 1.0
添加回答
舉報