| Author |
number formatting????
|
Kate Zoy
Ranch Hand
Joined: Feb 11, 2004
Posts: 33
|
|
i have an int (unknown lenght) that i need to format so there's a comma every 3 digits, like "1,000,203,2203". I know about DecimalFormat df1 = new DecimalFormat(), but I'm not quite sure what to put in the parentheses. If I knew the int was 4 digits, I could do "0,000", but I'm not sure how to go about formatting an unknown number of digits. Let me know! Thanks!
|
 |
Kate Zoy
Ranch Hand
Joined: Feb 11, 2004
Posts: 33
|
|
Turns out that even though I still don't know how to format my number, I have a bigger problem... I take in a string, which could be an integer of any length, and I parse it into an integer. Turns out that Integer.parseInt() doesn't work (in my case) for integer longer than 9 digits! I'm not sure what is going on! Help! Am i using the wrong type? Are integers not allowed 10 digits or more? Let me know! Thanks Alot!
|
 |
Tim West
Ranch Hand
Joined: Mar 15, 2004
Posts: 539
|
|
You're right - Integers (and ints) are stored in four bytes, and so are limited in size from -(2^31) to 2^31-1. I can't remember exactly what those numbers are but it's around 2 billion I think - so yes, 9 digits at most. In any case, use longs for a bigger range (-(2^63) to 2^63-1), or consider the BigInteger class if you truly need no boundaries. You can use the constructor that takes a String parameter to parse into a BigInteger. Cheers, --Tim
|
 |
Tim West
Ranch Hand
Joined: Mar 15, 2004
Posts: 539
|
|
Seems people politely ignored my mistake. 2 billion (2 000 000 000) is of course 10 digits, not 9. In any case, the actual range for ints is [-2,147,483,648 to 2,147,483,647]. For longs it's [-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807]. --Tim
|
 |
Eddie Vanda
Ranch Hand
Joined: Mar 18, 2003
Posts: 281
|
|
Hi Tim, Just a light hearted technical comment, on a multimeter that would be called "nine and a half digits"! Ed
|
The nice thing about Standards is that there are so many to choose from!
|
 |
zak miller
Greenhorn
Joined: Jun 24, 2004
Posts: 1
|
|
Should get 538,927,393
|
 |
Kate Zoy
Ranch Hand
Joined: Feb 11, 2004
Posts: 33
|
|
Thanks, that helps alot! I'll go try the BigInteger right now! Thanks again, Kate
|
 |
 |
|
|
subject: number formatting????
|
|
|