|
-
Senior Member
[F8][HELP] I want a float number
I use a lot of equations in my game and most of the time I can use the int() but not all the time. I get huge numbers like 1.123456789 witch I have to calculate and it slows flash down. I would like the number 1.123456789 to round to 1.1235. I think the Math.round takes off too much. what are my options.
CEO OF
-
Senior Member
Code:
Math.round(1.123456789*10000)/10000
But I'm quite sure that this won't speed up your movie.
-
Flash / Php game designer
Code:
result = int((some_number)*10000)/10000;
Convert to integer then multiply the number by 10000, this gives 11234. Now divide it by 10000, to get your number to 4 decimal places.
-
Senior Member
Aldarn thanx so much. walnoot I don't know if you ever made a huge game that uses a lot of math in your functions, but if you did you know that if your storing 100's of vars, 1.123456789 takes up way more bits than 1.234. A cpu uses less power to calculate 1.4 * 1.4 than 1.4533234 * 1.4234453 and If you need to do this calculation 100's of times a sec than...............I think you get the point.
CEO OF
-
Senior Member
So calculating 100's of vars to 4 decimal places 100 times a second won't do much to your cpu?
-
Senior Member
maybe I'm wrong but, my game is running faster.
CEO OF
-
Senior Member
Well, that's what counts
-
Flash / Php game designer
 Originally Posted by walnoot
So calculating 100's of vars to 4 decimal places 100 times a second won't do much to your cpu?
Thats better than his to 9 decimal places, which saves 5 bits per calculation (and saves alot of bitwise processing). Thats 500 bits/frame (62.5 bytes) and its likely to be over 20fps so that saves over 1k/sec and a hell of a lot of processing... hence its alot more efficient .
P.S. got a preview of the game?
-
Untitled-1.fla
 Originally Posted by zervell
1.123456789 takes up way more bits than 1.234. A cpu uses less power to calculate 1.4 * 1.4 than 1.4533234 * 1.4234453 and If you need to do this calculation 100's of times a sec than...............I think you get the point.
That's not correct. A floating point is a floating point, it doesn't matter if it's 1.4 or 1.4245323423. If you calculate var1*var2 where both have the value of 1.4 it won't be any faster than if they were 1.4245323423. A simple test will confirm this.
-
M.D.
AS3 has a this function toFixed, which can limit or add decimal points
var num = 4.3129836
trace( num.toFixed(2) ) // 4.31
var num = 4
trace ( num.toFixed(2) ) // 4.00
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|