Home arrow static arrow Java Programming [Archive] - BigDecimal get 18.1 instead of 18.000 ?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - BigDecimal get 18.1 instead of 18.000 ?
This topic has 4 replies on 1 page.

Posts:3,369
Registered: 24.10.97
BigDecimal get 18.1 instead of 18.000 ?  
Aug 6, 2004 7:26 AM



 
I get a decimal value from an SQL database (MS SQL Server with jTDS JDBC driver). The output of

System.out.println("nd: "+bd);

is "18.000000"

How can i just get the significant decimal places? In this case "18", for a value "12.305000" only "12.305", etc. ?
 

Posts:19,725
Registered: 9/26/01
Re: BigDecimal get 18.1 instead of 18.000 ?  
Aug 6, 2004 7:28 AM (reply 1 of 4)



 
java.text.NumberFormat and family.
 

Posts:24,036
Registered: 2/3/03
Re: BigDecimal get 18.1 instead of 18.000 ?  
Aug 6, 2004 7:34 AM (reply 2 of 4)



 
BigDecimal.setScale()
 

Posts:3,369
Registered: 24.10.97
Re: BigDecimal get 18.1 instead of 18.000 ?  
Aug 6, 2004 9:00 AM (reply 3 of 4)



 
setScale() cuts of places, e.g. "16.1234" will be cut to "16.12" for scale of 2. but i want all number scaled to the last (right-most) number that is not null. The only solution i found was DecimalFormat "0.#".
 

Posts:24,036
Registered: 2/3/03
Re: BigDecimal get 18.1 instead of 18.000 ?  
Aug 6, 2004 9:44 AM (reply 4 of 4)



 
setScale() cuts of places, e.g. "16.1234" will be cut
to "16.12" for scale of 2. but i want all number
scaled to the last (right-most) number that is not
null. The only solution i found was DecimalFormat
"0.#".

Ah. Yes, DecimalFormat is what you want for dropping trailing zeroes.
 
This topic has 4 replies on 1 page.