1.50 instead of 1.5....how?

while adding floats, how do i get the trailing 0? cause flash just seems to terminate it! and also is there a way to fix the number of digits after the decimal place?

aren’t they the same thing?

They are.

Do you know how floating point math works?
Floating Point

Are you asking about representing a float as a string with x number of decimal digit
toFixed()

Also look at toPrecision in case you need it later.

I didnt find those in the help manual sirisian…i am using AS2, can you help in some more detail.

And you all are right, 1.5 is same as 1.50 in math…but you see i am setting up the score system for “money” and in monetary system 1.5(five cent) and 1.50(fifty cent) are different. And this is also the reason i need 2 fixed decimal places in the number.

if i do 1.50+1.50, it will give 3, but i want 3.00…do you guys see my problem now?

[quote=bluemagica;2326495]I didnt find those in the help manual sirisian…i am using AS2, can you help in some more detail.

And you all are right, 1.5 is same as 1.50 in math…but you see i am setting up the score system for “money” and in monetary system 1.5(five cent) and 1.50(fifty cent) are different. And this is also the reason i need 2 fixed decimal places in the number.

if i do 1.50+1.50, it will give 3, but i want 3.00…do you guys see my problem now?[/quote]

If you can’t find a better way, couldn’t you just check for the length and add a zero if necessary?

That is a make shift way, i am looking for some actual way out!

Hmm, I thought I told everyone to use AS3 a while back. I guess the word didn’t get around. AS2 has no native method for turning a Number into a fixed type.

var n1:Number = 1.5;
var n2:Number = 1.5;
var n3:Number = n1 + n2;
var n1Plusn2:String = (n3 * 100).toString();
var indexOfPeriod:int = n1Plusn2.indexOf(".");
n1Plusn2 = n1Plusn2.substring(0, indexOfPeriod - 1) + “.” + n1Plusn2.substr(indexOfPeriod, 2);

something like that. You might have to test it.

Here’s the documentation for string.

Also this isn’t really game programming related. Remember to say the language you are using or people might assume it’s AS3.

cool code sirisian but i would say its safe to say that the chancs of it being as2 is still pretty high so dont assume nothing

Maybe a bit late, but these two functions might be useful:

// turn a number into a currency string 
function toCurr(num:Number):String {
	var currency:String = "£";
	var majUnit:Number = Math.floor(num);
	var minUnit:Number = Math.round((num - majUnit) * 100);
	var majUnitStr:String = String(majUnit);
	var minUnitStr:String;
	minUnit < 10 ? minUnitStr = "0" + String(minUnit) : minUnitStr = String(minUnit);
	return currency + majUnit + "." + minUnitStr;
}
// turn a currency string into a number 
function fromCurr(currency:String):Number {
	var str:String = currency.substr(1);
	return parseFloat(str);
}
//testing - note the subtle difference if you want to perform any maths functions on currency strings
var a:Number = 1.50;
trace("The sum of two numbers is " + (a + a));
trace("The sum of two currency amounts is " + toCurr(a + a));
var b:String = "£1.50";
trace("The sum(!) of two currency strings is " + (b + b));
trace("The sum of two currency amounts is " + (fromCurr(b) + fromCurr(b)));

I would think the easiest way is to have a number that represents currency, and just use cents, don’t bother with dollars/pounds. So to add £1 you actually add 100. Then for the display use a custom toString method that uses the length of the number, and if it is less than three add “£0.” to the start, and if it is greater than three change it to “£” + (all the digits except the last two) + “.” + (the last two digits).

umm guys, thanks for all the help, but i have managed to solve it using a makeshift way! But Still those were really a great help in my learning