Jump to content
Sign in to follow this  
j-man

Random number problem

Recommended Posts

I have a script that creates a random number. The problem is that it creates numbers like 12.5334, 53.242, etc... Is it possible to have those numbers rounded to the nearest whole number rock.gif

thanks

Share this post


Link to post
Share on other sites
I have a script that creates a random number. The problem is that it creates numbers like 12.5334, 53.242, etc... Is it possible to have those numbers rounded to the nearest whole number rock.gif

thanks

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_number = _number - (_number % 1);

Share this post


Link to post
Share on other sites

that's not the nearest whole number btw. that's the last whole number.

example: 9.999 is 9 then. and not 10.

normally it doesn't matter but one should know what he's doing smile_o.gif

Share this post


Link to post
Share on other sites
that's not the nearest whole number btw. that's the last whole number.

example: 9.999 is 9 then. and not 10.

normally it doesn't matter but one should know what he's doing smile_o.gif

You're right, I haven't read carefully, my apologies!  tounge_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_number = (_number+0.5) - ((_number+0.5) % 1);

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×