Convert Java Number to BigDecimal : best way

前端 未结 3 1059
离开以前
离开以前 2020-12-29 01:11

I am looking for the best way to convert a Number to a BigDecimal.

Is this good enough?

Number number;
BigDecimal big = new BigDecimal(number.toStrin         


        
3条回答
  •  梦谈多话
    2020-12-29 01:27

    The best way is

    BigDecimal.valueOf(myDouble);
    

    It's the same internally, but it's an overloaded function that works also for longs and it's optimized for frequently used longs value. So it's more standard, simple and easy to remember.

    Source

提交回复
热议问题