View comments | RSS feed

floor (Math.floor method)

public static floor(x:Number) : Number

Returns the floor of the number or expression specified in the parameter x. The floor is the closest integer that is less than or equal to the specified number or expression.

Availability: ActionScript 1.0; Flash Player 5 - In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports.

Parameters

x:Number - A number or expression.

Returns

Number - The integer that is both closest to, and less than or equal to, parameter x.

Example

The following code returns a value of 12:

Math.floor(12.5);

The following code returns a value of -7:

Math.floor(-6.5);

Flash CS3


Comments


No screen name said on Jan 31, 2008 at 6:17 AM :
what's wrong with math.floor function?
why (Math.floor(18.83 * 100)) returns 18.82?
no such problem with numbers like 28.83, 38.83 etc.
please help!
djtechwriter said on Jan 31, 2008 at 4:01 PM :
I'm not sure where your error is. If I try this:
trace(Math.floor(18.83*100));
I get this as the output:
1882
As expected.
El Destructor Estelar said on Feb 1, 2008 at 2:24 AM :
with numbers like 28.83, 38.83 function returns 2883, 3883,
but if we put there 18.83 we get 1882.
djtechwriter said on Feb 1, 2008 at 11:15 AM :
Ah, i see. my mistake. you're correct it should return 1883. I'll log a bug.
richard_gamelearn said on Feb 5, 2008 at 3:23 PM :
This bug with the floor function is pretty odd:

var val:Number = parseFloat("3.43");
trace(Math.floor(val * 1000000)); // 3429999

But changing the multiplier to a smaller or bigger power of ten gives the expected results: 343000 and 34300000.
Also changing the value to "3.42" or just using a number gives the correct result.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00001826.html