/**
* The value is rounded (Reserved 2 decimal places) after formatting into the amount of the form
*
* @param num Value (number or string)
* @return Amount format string, such as ' 1,234,567.45 '
* @type String
*/
function FormatCurrency (num) {
num = num.tostring (). Replace (/\$|\,/g, ");
if (IsNaN (num))
num = "0";
Sign = (num = = (num) = Math.Abs (num));
num = Math.floor (num*100+0.50000000001);
cents = num%100;
num = Math.floor (num/100). toString ();
if (cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor (num.length-(1+i))/3); i++)
num = num.substring (0,num.length-(4*i+3)) + ', ' +
Num.substring (num.length-(4*i+3));
Return ((sign)? ': '-') + num + '. ' + cents);
}
/**
* The value is rounded (reserved 1 decimal places) after formatting into the amount of the form
*
* @param num Value (number or string)
* @return Amount format string, such as ' 1,234,567.4 '
* @type String
*/
function Formatcurrencytenthou (num) {
num = num.tostring (). Replace (/\$|\,/g, ");
if (IsNaN (num))
num = "0";
Sign = (num = = (num) = Math.Abs (num));
num = Math.floor (num*10+0.50000000001);
cents = num%10;
num = Math.floor (NUM/10). toString ();
for (var i = 0; i < Math.floor (num.length-(1+i))/3); i++)
num = num.substring (0,num.length-(4*i+3)) + ', ' +
Num.substring (num.length-(4*i+3));
Return ((sign)? ': '-') + num + '. ' + cents);
}
JS makes currency formatting for numbers and retains two decimal places, decimals with 0 complement