I need to have data formatted in a specific way but what I have only works sometimes. I have a field of numbers that are made up of 9 digits (xxxxxxxxx). I need them to be displayed in a specific format.
Place a decimal point just before the fourth digit from the right.
If the digits before the fourth digit from the right are all zeros, place a single zero before the decimal point.
If the digits before the fourth digit from the right are not all zeros, remove leading zeros and display all digits before the decimal point.
Examples:
000013148 becomes 1.3148
000000138 becomes 0.0138
004640000 becomes 464.0000
Below is the javascript that will not work with example 2 above:
var str = data.extract(‘FIELD’,0);
str = str.replace(/\b0+/g, ‘’);
var len = str.length;
str.substring(0,len-4) + “.” + str.substring(len-4,len);