A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [F8][HELP] I want a float number

  1. #1
    Senior Member zervell's Avatar
    Join Date
    May 2004
    Posts
    259

    [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

  2. #2
    Senior Member walnoot's Avatar
    Join Date
    Apr 2005
    Posts
    751
    Code:
    Math.round(1.123456789*10000)/10000
    But I'm quite sure that this won't speed up your movie.

  3. #3
    Flash / Php game designer
    Join Date
    Mar 2005
    Location
    UK
    Posts
    253
    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.

  4. #4
    Senior Member zervell's Avatar
    Join Date
    May 2004
    Posts
    259
    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

  5. #5
    Senior Member walnoot's Avatar
    Join Date
    Apr 2005
    Posts
    751
    So calculating 100's of vars to 4 decimal places 100 times a second won't do much to your cpu?

  6. #6
    Senior Member zervell's Avatar
    Join Date
    May 2004
    Posts
    259
    maybe I'm wrong but, my game is running faster.
    CEO OF

  7. #7
    Senior Member walnoot's Avatar
    Join Date
    Apr 2005
    Posts
    751
    Well, that's what counts

  8. #8
    Flash / Php game designer
    Join Date
    Mar 2005
    Location
    UK
    Posts
    253
    Quote 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?

  9. #9
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    Quote 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.

  10. #10
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    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
    lather yourself up with soap - soap arcade

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center