Groups | Blog | Home
all groups > flash actionscript > december 2005 >

flash actionscript : determining whether a number is float


guanomike
12/8/2005 11:00:47 PM
yet another silly question: how do I determine if a number is actually a float? (I want 2.00 to return true also).
NSurveyor
12/8/2005 11:52:10 PM
To see if a number isn't whole, you could use:

myNum = 2.4534;
if(Math.round(myNum)!=myNum){
trace("The number is a float!");
}

You say you want it to work for 2.00 but how are you going to hae 2.00? (2.00
as a number is still going to be plain old 2) Is your number actually going to
be a string? If so, just look for a '.' in the string:

myNum = "2.00";
if(myNum.indexOf('.')!=-1){
trace("The 'number' is a float!");
}

or

myNum = "2.00";
if(myNum.split('.').length>1){
trace("The 'number' is a float!");
}
vt_aravinth
12/9/2005 12:00:00 AM
Great , Thank you very much.

Is this a standard procedure or your own logic !?
(just to know, nothing intentonal :-) ).
vt_aravinth
12/9/2005 3:49:04 AM
Hi,

NSurveyor
12/9/2005 4:13:25 AM
I think this should do it:

var myNum = 2.987654321;
var places = 3;
var roundedNum = Math.round(myNum*Math.pow(10,places))/Math.pow(10,places);
AddThis Social Bookmark Button