I have created a format that allows two digits after the decimal, for example 99.99
or 55.55
etc. I would like to make it allow 99.999
instead of two. Not sure where the problem is.
function formatNumber (nStr) {
nStr = String(nStr)
nStr = nStr.replace(/\,/g, '')
nStr = trimNumber(nStr)
if ($.isNumeric(nStr)) {
nStr = String(parseFloat(nStr).toFixed(2))
nStr += ''
x = nStr.split('.')
x1 = x[0]
if (x.length > 1) {
if (x[1].length > 2) {
var thirddigit = x[1].substr(2, 1)
var addone = false
if (Number(thirddigit) >= 5) {
addone = true
}
x[1] = x[1].substr(0, 2)
if (addone) {
var y = Number(x[1]) + 1
x[1] = y
}
}
}
x2 = x.length > 1 ? '.' + x[1] : ''
var rgx = /(\d+)(\d{3})/
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2')
}
if (x.length > 1) {
if (x[1].length == 1) {
x2 = '.' + x[1] + '0'
}
if (x[1].length == 0) {
x2 = '.00'
}
} else {
if (x1 != '') {
x2 = '.00'
}
}
if (getLeft(x1 + x2, 1) == '.') {
return '0' + x1 + x2
} else {
return x1 + x2
}
} else {
return ''
}
}