Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retain trailing zeroes when converting BigDecimal to String

I have to convert a BigDecimal value, e.g. 2.1200, coming from the database to a string. When I use the toString() or toPlainString() of BigDecimal, it just prints the value 2.12 but not the trailing zeroes.

How do I convert the BigDecimal to string without losing the trailing zeroes?

like image 597
user68883 Avatar asked Jun 17 '15 13:06

user68883


1 Answers

try this..

MathContext mc = new MathContext(6); // 6 precision
BigDecimal bigDecimal = new BigDecimal(2.12000, mc);
System.out.println(bigDecimal.toPlainString());//2.12000
like image 101
Hiren Avatar answered Oct 06 '22 23:10

Hiren