Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting String as double values

 
Chidananda Sulur
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ October 08, 2004: Message edited by: Nigel Browne ]
 
Edwin Keeton
Ranch Hand
Posts: 214
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you use the BigDecimal class to display the correct format?
Like this:

 
Chidananda Sulur
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, The decimalformat api seems to resolve the issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic