aspose file tools*
The moose likes Beginning Java and the fly likes Formatting String as double values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Formatting String as double values" Watch "Formatting String as double values" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Formatting String as double values