Custom non-standard number formating

I’m trying to format a number so that it is padded with 0’s to always show 9 digits. eg 10045 = 000010045 but with commas in specific places.

Getting the padding is fine, but the format property of the numeric label doesn’t follow my comma layout.

For example I’m using the format #00,0000,000 where (right to left) the first three digits represent one group, the next four represent another, and the last two represent another, all separated by the commas.

However even with the above mask the display defaults to 000,000,000 where there is a comma every three digits.

Am I setting the wrong mask or am I going to have to turn the number into a string and format it manually and display it as text?

1 Like

If the pattern system used by the PMINumericLabel and PMIFormattedTextField components is anything like Java’s DecimalFormat, then I don’t think this is possible.

In DecimalFormat, you can set the grouping size (how many numbers between commas) but it has to be consistent:
https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html

Thankfully this isn’t so bad to script yourself:

n = str(4)								# convert number to string
n = n.zfill(9)							# pad to 9 zeros
n = n[:2] + ',' + n[2:6] + ',' + n[6:]	# insert custom grouping seperators
3 Likes