目录
- 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内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复