我是靠谱客的博主 感动万宝路,这篇文章主要介绍double类型转BigDecimal的正确姿势有两种,现在分享给大家,希望可以做个参考。

目录

      • double类型转BigDecimal的正确姿势有两种

double类型转BigDecimal的正确姿势有两种

  1. BigDecimal.valueOf(Double_Value)
  2. 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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部