*
The moose likes Java in General and the fly likes How to format large number correctly? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to format large number correctly?" Watch "How to format large number correctly?" New topic
Author

How to format large number correctly?

Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Hi friends:

I want to display a large number to jsp reading from database(Oracle).The number is "1111111111". The number in database is "1111111111" excactly and it is Float (126) . But after it displayed to jsp,it become "1111111112" ?! why JVM auto format Float number? The number "1111111112" is not what I want to see. I use NumberFormat class to format it,but no luck ;-(

My code is:


If I input number 300000000,it will display 3E. no! Why it couldn't display correctly? How to format large number for display correctly? Thks!! :roll:
[ January 13, 2005: Message edited by: Bear Bibeault ]

When I face C# and Java I choose Java.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Moving to the Java in General(intermediate) forum since this isn't a JSP-specific issue.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
The problem isn't with formatting; it's with the way floating point numbers are stored internally. Floats are not exact and introduce round-off error. If you want information, you can google or use the search tool here at the Ranch. To make things short here, though, I'll just suggest that you use the BigInteger class in order to store an exact representation of the number.

HTH

Layne


Java API Documentation
The Java Tutorial
 
jQuery in Action, 2nd edition
 
subject: How to format large number correctly?
 
Similar Threads
how to convert to a exact double from float expression
formatting to 4 decimal places
Widening conversion from int to float..
Parse decimal value
Setting unveven intervals in JFreechart