I have String containing only numbers and a comma in followin format nnnnnnnnn,n where n is number 0 - 9. E.g. the right value would be 121231234,1
I have to convert it into format 12 123 1234,1
How should I code it properly using Java's Formatter classes? I can code that using loops etc. but I do not want to code such code. So, anyone know how to do it with formatters. I have to support JDK 1.4.
I tried a code below, but spaces in the last line does not appear between numbers. I know that might approach can also be wrong. Could someone please, how handle this formatting nicely.
String s = "121231234,1"; double d = Double.parseDouble(s);
I got close to the desired output by manipulating the DecimaFormatSymbols, but I cant get it to do the variable grouping widths.
[ March 20, 2006: Message edited by: Garrett Rowe ]
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Joined: Jan 17, 2006
Garrett: ...but I cant get it to do the variable grouping widths
A closer look at the documentation reveals that a DecimaFormat object won't do variable width parsing.
The grouping size is a constant number of digits between the grouping characters, such as 3 for 100,000,000 or 4 for 1,0000,0000. If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So "#,##,###,####" == "######,####" == "##,####,####".
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com