Good morning,
I have made a function that adds interpunction marks to a value, for
example the value 10000 gets changed to 10.000, 100000 to 100.000 and
so forth.
The function work fine, but I'm trying to make it reusable so that i
can use it in a large scale project. That's where the problem comes
up.
This is what the working code looks like:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var outputNumber:Number = 10000 // input value
var outputString:String = new String();
function init ()
{
outputString = String(Number(outputNumber));
interpunk (outputString);
trace(outputNumber); // output is 10000
trace(outputString); // output is 10.000
}
function interpunk (par1):Void
{
trace(par1)
switch (par1.length)
{
case 4 :
outputString = String(par1.charAt (0) + "." +
par1.slice (1))
break;
case 5 :
outputString = String(par1.charAt (0) + par1.charAt (1)
+ "." +
par1.slice (2))
break;
case 6 :
outputString = String(par1.charAt (0) + par1.charAt (1)
+
par1.charAt (2) + "." + par1.slice (3))
break;
default :
outputString = String(par1)
break;
}
}
init ();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
So i tried to make it reusable, so i tried this(changed outputString to par1).
But now the value comes out unchanged so 10000 stays 10000, while i
expected it to become 10.000.
I hope someone can help i the right direction.
This is what the non working code looks like :
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function interpunk (par1):Void
{
trace(par1)
switch (par1.length)
{
case 4 :
par1 = String(par1.charAt (0) + "." + par1.slice (1))
break;
case 5 :
par1 = String(par1.charAt (0) + par1.charAt (1) + "." +
par1.slice (2))
break;
case 6 :
par1 = String(par1.charAt (0) + par1.charAt (1) +
par1.charAt (2) +
"." + par1.slice (3))
break;
default :
par1 = String(par1)
break;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders