FAR-Warrior 0 Posted November 27, 2002 Hi, I have a problem with a script, i want to have an integer of a result... For example : Time = 10.585 Result must be 10 How to do that ?? Share this post Link to post Share on other sites
ralphwiggum 6 Posted November 27, 2002 sorry! wrong code! Share this post Link to post Share on other sites
bn880 5 Posted November 28, 2002 Somehow I always thought % and mod returned the remainder portion. EDIT: I would have tried </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">Time = 10.585; Time = Time - (Time mod 1); <span id='postcolor'> Share this post Link to post Share on other sites
FAR-Warrior 0 Posted November 28, 2002 And if Time is a variable, like _time in a script Share this post Link to post Share on other sites
bn880 5 Posted November 28, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (FAR-Warrior @ Nov. 27 2002,20:50)</td></tr><tr><td id="QUOTE">And if Time is a variable, like _time in a script <span id='postcolor'> Forcing me to think? I think not. copy it into another variable... no more problems. _myTime = _time; code code code Share this post Link to post Share on other sites
ralphwiggum 6 Posted November 28, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (bn880 @ Nov. 28 2002,01:32)</td></tr><tr><td id="QUOTE">Somehow I always thought % and mod returned the remainder portion. Â EDIT: I would have tried </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">Time = 10.585; Time = Time - (Time mod 1); <span id='postcolor'><span id='postcolor'> OOPS! my bad! bn880 is correct.... Â Share this post Link to post Share on other sites
Prospero 1 Posted November 28, 2002 I edited a previous post of mine: Say I want to round a number (let's say to three decimal places). I could just use: _x = (_x + 0.0005 - ((_x + 0.0005) % 0.001)) This rounds _x up perfectly well if _x is positive. But instead, let's say _x is negative. Now, I may want to round down rather than up (for the sake of symmetry), so I use this: _x = (_x - 0.0005 - ((_x - 0.0005) % 0.001)) The problem is I have to test _x first (with a condition) to see if it is positive or negative, and conditions are very slow in OFP. I'm trying to do it without using a condition - in order to speed things up. There is a way to do this - you simply avoid rounding a variable when it goes negative in the first place. Just add an integer value to it large enough that the variable will always be positive. Now do the rounding. Then subtract the same integer from it to return to the original negative value. Now you have rounded symmetrically without an extra (slow) condition. To round a number to integer value: _x = (_x + 0.5 - ((_x + 0.5) % 1)) Prospero Share this post Link to post Share on other sites