| Author |
formatting double value
|
Sandeep Sirsekar
Greenhorn
Joined: Apr 09, 2008
Posts: 16
|
|
hi all
can someone please help me out ,
i want to parse double to precision length of 4 digit after '.'
ive tried
System.out.format("%1$f.4", 12.3456789123456789);
System.out.format("%1$f2.4", 12.3456789123456789);
so can anyone tell me what to do to get
12.3456
thanks in advance.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Use %.4f or %1.4f
The .4 indicates the number of decimals.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
Rob is correct; the problem was that you have the .4 bit after the s.
But you will never get 12.3456 from that number. It will be rounded to 12.3457. You would have to round down, possibly using methods of the BigDecimal and MathContext classes.
|
 |
 |
|
|
subject: formatting double value
|
|
|