PDA

View Full Version : French currency and such


newbie50
02-04-2011, 12:30 PM
Hello,
Below is a code in Actionscript 3 we're using that separates 1000s with commas and two decimals at the end. So something like 100000.00 is 100,000.00
We need to change it to a French version. We're told it involves a space and commas. So $100.00 is 100,00 $ in French.
And 500,000.00 would be 500 000,00

Is there an easy way to change the code we're using to reflect the change? Or is there some other code you can suggest.
Thanks for the help.


function numberFormat(number:*, maxDecimals:int = 2, forceDecimals:Boolean = false, siStyle:Boolean = true):String
{
var i:int = 0;
var inc:Number = Math.pow(10, maxDecimals);
var str:String = String(Math.round(inc * Number(number))/inc);
var hasSep:Boolean = str.indexOf(".") == -1, sep:int = hasSep ? str.length : str.indexOf(".");
var ret:String = (hasSep && !forceDecimals ? "" : (siStyle ? "," : ".")) + str.substr(sep+1);
if (forceDecimals) {
for (var j:int = 0; j <= maxDecimals - (str.length - (hasSep ? sep-1 : sep)); j++) ret += "0";
}
while (i + 3 < (str.substr(0, 1) == "-" ? sep-1 : sep)) ret = (siStyle ? "." : ",") + str.substr(sep - (i += 3), 3) + ret;

return str.substr(0, sep - i) + ret;

}

audiopro
02-04-2011, 03:32 PM
The formatting is only used for human readability and has no bearing on the actual amount or indeed language.

£100,000.00 would read the same as €100,000.00, as the currency symbol precedes the amount in both cases.

newbie50
02-08-2011, 12:42 PM
audiopro, thanks for your input, but I'm told by our French colleagues that the style for French numbers and currency follows the following format:
100 000,00$ for money and 100 000,00 for numbers.

Any help on tweaking the code below to reflect this would be greatly appreciated. Thanks for your time and help.

newbie50
02-08-2011, 01:13 PM
Hello,

I made a tweak to the code so that I could get numbers to display in the following format: 100 000,00
Would anyone be able to review it and tell me if there's anything wrong with the way I've done it? I'm new to Actionscript 3 and would appreciate any help.
Thanks.

function numberFormat(number:*, maxDecimals:int = 2, forceDecimals:Boolean = false, siStyle:Boolean = true):String
{
var i:int = 0;
var inc:Number = Math.pow(10, maxDecimals);
var str:String = String(Math.round(inc * Number(number))/inc);
var hasSep:Boolean = str.indexOf(".") == -1, sep:int = hasSep ? str.length : str.indexOf(".");
var ret:String = (hasSep && !forceDecimals ? "" : (siStyle ? "." : ",")) + str.substr(sep+1);
if (forceDecimals) {
for (var j:int = 0; j <= maxDecimals - (str.length - (hasSep ? sep-1 : sep)); j++) ret += "0";
}
while (i + 3 < (str.substr(0, 1) == "-" ? sep-1 : sep)) ret = (siStyle ? "," : " ") + str.substr(sep - (i += 3), 3) + ret;

return str.substr(0, sep - i) + ret;

}

audiopro
02-08-2011, 03:36 PM
Has the Euro(€) not caught on in their part of France then? :)