| Author |
Formatting String as double values
|
Chidananda Sulur
Greenhorn
Joined: May 10, 2000
Posts: 14
|
|
Hi, This may be a simple one but need help. I want to convert a string to a double value and return the same without losing the formatting. The sample code is as enclosed. public class TestDouble { private static final String AMT = "100000000.376"; public static void main(String[] args) { System.out.println("amount is "+AMT); System.out.println("amount in double is "+Double.valueOf(AMT)); } } The output is amount is 100000000.376 amount in double is 1.00000000376E8 I want the second value also to be displayed as 100000000.376 stored as a double without the exponential formatting. Please let me know any thoughts. Thanks
|
Chidu
|
 |
Nigel Browne
Ranch Hand
Joined: May 15, 2001
Posts: 673
|
|
[ October 08, 2004: Message edited by: Nigel Browne ]
|
 |
Edwin Keeton
Ranch Hand
Joined: Jul 10, 2002
Posts: 214
|
|
Could you use the BigDecimal class to display the correct format? Like this:
|
SCJP, SCWCD
|
 |
Chidananda Sulur
Greenhorn
Joined: May 10, 2000
Posts: 14
|
|
|
Thanks, The decimalformat api seems to resolve the issue.
|
 |
 |
|
|
subject: Formatting String as double values
|
|
|