Gday Dennis
thanks very much for your efforts...
While I'm not new to programming, this is probably my first attempt to
modify my own JavaScript.
I have made a couple of minor additions to the code you supplied, and
honestly, didnt have the faintest idea where to start because the syntax /
object model / typing etc are so vastly different from the code I am used to
writing.
Here 'tis... prolly a bit longhand and I'm sure theres more 'efficient' ways
to do the same thing but lets face it its prolly only a couple of cpu cycles
and additionally, those cpu cycles are not run on /my/ server
)
Thanks Again.
-Douglas
/// ///
/// JavaScript FormatCurrency Function - FormatCurrency.js ///
/// ///
/// This script will format positive money values. Pass it a number
/// with or without decimal digits. It will be formatted with the currency,
/// thousands, and decimal symbols passed to it.
/// PASSED PARAMETERS
/// theNumber - the number to be formatted
/// theCurrency - the currency symbol
/// theThousands - the thousands separator
/// theDecimal - the decimal separator
function isThousands(position)
{
if (Math.floor(position/3)*3==position) return true;
return false;
};
function formatMoney (theNumber,theCurrency,theThousands,theDecimal)
{
if (theDecimal==undefined)
{
var theDecimalDigits = "";
} else {
var theDecimalDigits =
Math.round((theNumber*100)-(Math.floor(theNumber)*100));
}
theDecimalDigits= "" + (theDecimalDigits + "0").substring(0,2);
theNumber = "" + Math.floor(theNumber);
var theOutput = theCurrency;
for (x=0; x<theNumber.length; x++)
{
theOutput += theNumber.substring(x, x+1);
if (isThousands(theNumber.length-x-1) && (theNumber.length-x-1!=0))
{
theOutput += theThousands;
};
};
if (theDecimal!=undefined)
{
theOutput += theDecimal + theDecimalDigits;
}
return theOutput;
};
----- Original Message -----
From: "Dennis M. Marks" <
[email protected]>
Newsgroups: comp.lang.javascript
Sent: Thursday, April 08, 2004 9:03 AM
Subject: Re: Formatting Number With Thousands Separator