This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes number convert Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 1865
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


1. Have fun @ http://faq.javaranch.com/java/JavaRaq
2. Looking for simple infix2postfix conversion and postfix evaluation package? Click here
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: 1865
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
 
Similar Threads
Formatting numbers
lucene estimate index size, search time
Convert DateTime to TimeStamp
Reading a stream from a socket
Worlds cheapest car - Rupees 1 lakh car ($2000)