概述
目录
- double类型转BigDecimal的正确姿势有两种
double类型转BigDecimal的正确姿势有两种
- BigDecimal.valueOf(Double_Value)
- new BigDecimal(String.valueOf(Double_Value))
原因:
BigDecimal最佳实践是支持String类型的构造方法。
Note: For values other than float and double NaN and ±Infinity, this constructor is compatible with the values returned by Float.toString and Double.toString. This is generally the preferred way to convert a float or double into a BigDecimal, as it doesn’t suffer from the unpredictability of the BigDecimal(double) constructor.
public BigDecimal(String val) {
this(val.toCharArray(), 0, val.length());
}
最后
以上就是感动万宝路为你收集整理的double类型转BigDecimal的正确姿势有两种的全部内容,希望文章能够帮你解决double类型转BigDecimal的正确姿势有两种所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复