```
function addLead(strDollar, len, leadChar = "0") {
result = strDollar;
while(result.length < len)
result = leadChar + result;
return result;
}
```

or if you don't know if the period and cents will be included:

```
// adds leading characters specified by leadChar, up
// to alength of len, on the string strDollar.
// takes into account if there is a period and/or cents
function addLead(strDollar, len, leadChar = "0") {
result = strDollar;
dot = strDollar.indexOf('.') === -1 ? 0 : strDollar.len - strDollar.indexOf('.');
while(result.length < (len+dot))
result = leadChar + result;
return result;
}
```

To also add trailing zeros:

```
// adds leading characters specified by leadChar, up
// to alength of len, on the string strDollar.
// takes into account if there is a period and/or cents
// also adds trailing zeros unless the 4th param is set false.
function addLead(strDollar, len, leadChar = "0", addTrailingZeros = true) {
result = strDollar;
dot = strDollar.indexOf('.') === -1 ? 0 : strDollar.len - strDollar.indexOf('.');
while(result.length < (len+dot))
result = leadChar + result;
if(addTrailingZeros)
for(x=0; (x<3-dot); x++)
result = "0" + result;
return result;
}
```