- String 转 Double 失去精度解决办法。
String a = "4.56";
BigDecimal temp1 = BigDecimal.valueOf(Double.valueOf(a));
temp1 = temp1.multiply(BigDecimal.valueOf(100));
int sum1 = temp1.intValue();
String b = String.valueOf(sum1);
Log.d("tag", "onCreate: " + b); //456
- 去除末尾多余的 0
String a = "9.80";
String str = new BigDecimal(a).stripTrailingZeros().toPlainString();
Log.d(TAG, "onCreate: "+ str); //9.8
网友评论