"Custom" Data Format

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);

Give this a try instead. Basically just treats the first and second half separately and does a look ahead to see if the last 0 in the first part is followed by a period or not. If not, it’s removed.

var str = data.extract(‘FIELD’,0);
var len = str.length;
var str1,str2;

str1 = str.substring(0,len-4) + ".";
str2 = str.substring(len-4,len);
str1.replace(/0(?!\.)/g, '') + str2;

Mr. AlbertsN, your solution works for all the variations I’ve listed. Thank you sir.