我是靠谱客的博主 感动万宝路,最近开发中收集的这篇文章主要介绍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的正确姿势有两种所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部