wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes number convert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "number convert" Watch "number convert" New topic
Author

number convert

Jackie Wang
Ranch Hand

Joined: Apr 18, 2002
Posts: 315
any build in function can convert
a number 8000000000000
into
8, 000, 000, 000, 000
thanks!
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi Jackie,
you can use NumberFormatter for the purpose. here is a link for SUN's tutorial about it.
also here is a sample code i tried with it,

the output was,
Output:8,000,000,000
the only problem i found was- format() method doesn't accept long as simple argument even if we cast 8000000000 to long explicitly, it expects integer argument instead so i had to use double to specify that big value..
hope this helps.
regards
maulin
Jackie Wang
Ranch Hand

Joined: Apr 18, 2002
Posts: 315
Maulin,
thanks so much for the prompt reply.
However, I would like the number to be
8, 000, 000, 000 (with space)
Also,
for a string: "testingmessingtestingmessageasdasdasasdasasd" how can i arbitrary break the string into 10 character with a space in between? Thanks!
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi Jackie,
say you want to put a space at character position 'pos' and you have the string 'str' then you can write the following to achieve that,
str = "8000000000";
char space = ' ';
str = new StringBuffer(str).insert(pos,space).toString();
please let me know if this works. ive not tried this code...
regards
maulin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: number convert