Using MessageFormat, group decimal places

420 Views Asked by At

I am using MessageFormat. The current pattern is:

{0,number,#,###.######}

For 0.123456 it gives me

0.123456

which is expected. However I want to group the decimal places so that the display is

0.123 456

I would also like trailing zeros, so for 0.1234 the display would be

0.123 400

I can't seem to find the correct custom pattern for this

1

There are 1 best solutions below

4
SzaPe On

For the trailing zeros you could replace the # with 0 in the decimal places like "{0,number,#,###.000000}" See DecimalFormat#Special Pattern Characters

0   Number  Yes Digit
#   Number  Yes Digit, zero shows as absent