Convert Java Number to BigDecimal : best way -


i looking best way convert number bigdecimal.

is enough?

number number; bigdecimal big = new bigdecimal(number.tostring()); 

can lose precision tostring() method ?

this fine, remember using constructor of bigdecimal declare value can dangerous when it's not of type string. consider below...

bigdecimal valdouble = new bigdecimal(0.35); system.out.println(valdouble); 

this not print 0.35, infact be...

0.34999999999999997779553950749686919152736663818359375 

i'd solution safest because of that.


Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -

c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -