Skip to content
Advertisement

Convert Java Number to BigDecimal : best way

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

Is this good enough?

JavaScript

Can we lose precision with the toString() method ?

Advertisement

Answer

This is fine, remember that using the constructor of BigDecimal to declare a value can be dangerous when it’s not of type String. Consider the below…

JavaScript

This will not print 0.35, it will infact be…

JavaScript

I’d say your solution is probably the safest because of that.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement