I\'ve researched the subject somewhat before posting the question, but I couldn\'t find the answer.
Here is what I\'m trying to do:
input: a number 7-8 decim
I don't think you can use the DecimalFormat
grouping separator for this. From the Javadoc:
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 "#,##,###,####" == "######,####" == "##,####,####".
You can use ICU4J library's com.ibm.icu.text.DecimalFormat class for this same purpose. It supports variable length group size. For your particular case:
com.ibm.icu.text.DecimalFormatSymbols dfs = new com.ibm.icu.text.DecimalFormatSymbols();
dfs.setGroupingSeparator(' ');
com.ibm.icu.text.DecimalFormat df = new com.ibm.icu.text.DecimalFormat("0,000000,0", dfs);
This should print '0 123456 7' for a number like '1234567'.