1,案例
支付平台的機關是分,而業務系統的機關是元,是以傳到支付系統時要乘以100

@test
public void test_divide2() {
string payamountstr="1011";
float f=float.parsefloat(payamountstr);
float result=f/100f;
system.out.println(string.valueof(result*100));
}
運作結果:1010.99994
但是預期結果是:1011
2,解決方法:使用bigdecimal

public void test_divide() {
bigdecimal chanpayacount=new bigdecimal(payamountstr);
bigdecimal bssacount= chanpayacount.divide(new bigdecimal(100));
system.out.println("使用bigdecimal");
system.out.println(string.valueof(bssacount.multiply(new bigdecimal(100))));
運作結果:
使用bigdecimal
1011.00