Leading zero's and decimal point

I have code that adds leading zero’s to a currency field. I require the total digits/chars to be 9 (inclusive of the decimal point.

for instance 1441.34 becomes 001441.34

The code works well for for values in the thousands/10’s of thousands/100’s of thousands but adds an additional decimal point when converting values of less than 1000

for instance 40.50 becomes 0.0040.50
for instance 138.00 becomes .00138.00

I’m sure it’s something simple…could someone point me in the right direction?

The code I’m using is as follows:

var val2 = record.fields[“Total”];
val2 = val2.replace(/[^0-9.]/g, “”);
var t = “000000.00” + val2;
result2 = t.substr(t.length-9);

I do not understand why you want to use the regex. Just try the following code:

var val2 = record.fields["Total"];
var t = "000000000" + val2;
result = t.substr(t.length-9);
results.html(result);

Or did I miss an information? As long as your input value gives you the decimal values (that should be the case for currency fields), you do not need to check that.

This works to some extent, except that it still contains the $ sign which I don’t want/require in the result

Remove the $ (Currency Sign) from your mapper. Where you specify currency format.

Regards,
S