Last active
May 7, 2019 02:16
-
-
Save DeppWang/77fe719e8f5ba7fbed3aee54c5a4c71e to your computer and use it in GitHub Desktop.
Double数值默认下舍入保留一位小数,直接舍弃掉1位小数后的值
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Double roundDownDouble(Double value) { | |
BigDecimal b = new BigDecimal(String.valueOf(value));//BigDecimal(String val)可控,BigDecimal(double val)不可预测。(BigDecimal:不可变的,任意精度带符号的十进制数) | |
return b.setScale(1, BigDecimal.ROUND_DOWN).doubleValue();//下舍入 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment