dcsimg
A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: How can I round up a number in flash 4??

  1. #1
    Junior Member
    Join Date
    Sep 2000
    Posts
    14

    Post

    OK I trying to round up a number....for example:

    if i type in 5.4 I want to return 5,
    if is 5.9 I want to return 6.

    Can anybody help me?????

    I know is posible in JavaScript, math.floor.

    Thanks

    JT

  2. #2
    Member
    Join Date
    Aug 2000
    Posts
    66
    have x represent yhe number you want to round

    use if expressions

    if x <= 5.4
    set variable x = 5
    if x >= 5.5
    set variable x = 6


    This should work out

  3. #3
    Senior Member
    Join Date
    Mar 2000
    Posts
    191

    rounding

    You can also use the integer function...

    (Flash 4)
    Set Variable: "number" = int (x)
    where x is the non whole number

    (Flash 5)
    number = int(x);
    where x is the non whole number

    makes it really easy!

  4. #4
    Senior Member
    Join Date
    Mar 2000
    Posts
    191

    whoops

    nevermind, that's not really for rounding... that would make a 3.2 a 3 but it would also make a 3.9 a 3

    sorry, I'll try to find something better

  5. #5
    Senior Member
    Join Date
    Mar 2000
    Posts
    191

    here

    here you go... I sent you on the wrong track but this should get you back on...


    (Flash 5)

    if (x >= eval (int (x) add ".5")) {
    time = int (x) + 1;
    } else {
    time = int (x);
    }

    it even used the earlier wrong idea I had!

    hope it helps

  6. #6
    Senior Member
    Join Date
    Mar 2000
    Posts
    191

    shoot

    SOOORRRYYY!!!!

    time was a variable I was using in my test... here it is CORRECTLY...

    if (x >= eval (int (x) add ".5")) {
    x = int (x) + 1;
    } else {
    x = int (x);
    }


  7. #7
    Junior Member
    Join Date
    Sep 2000
    Posts
    14
    Thanks for your help but I know how to do that...
    what I need is some kind of formula so I don't have to test every posibility
    for example I need to round up every number from 0 - 100.
    Then I would need about 200 if statements.

    Maybe a loop?

    Thanks

    JT

    Originally posted by jtubert
    OK I trying to round up a number....for example:

    if i type in 5.4 I want to return 5,
    if is 5.9 I want to return 6.

    Can anybody help me?????

    I know is posible in JavaScript, math.floor.

    Thanks

    JT

  8. #8
    Senior Member
    Join Date
    Jul 2000
    Location
    Not on the dole any more
    Posts
    1,040
    joefouts has the right idea, but that's Flash5 code he's using...try this:

    Code:
    On (Release)
          Set Variable: "remainder" = number - int(number)
          If (remainder >= 0.5)
                Set Variable: "number" = int (number) + 1
          Else
                Set Variable: "number" = int (number)
          End If
    End On
    where the variable 'number' is the original value.
    [Edited by Stickman on 12-11-2000 at 10:51 AM]

  9. #9
    Senior Member
    Join Date
    Jul 2000
    Location
    Not on the dole any more
    Posts
    1,040
    Alternatively, I just thought up a single line solution:

    Code:
    Set Variable: "number" = INT(number) + (INT ((number - INT(number)) *2))
    Which I reckon should work.

  10. #10
    Senior Member
    Join Date
    Mar 2000
    Posts
    191

    Very Nice!

    Very nice Stickman! I will probably end up using that myself in the future. Good thinking!

  11. #11
    Junior Member
    Join Date
    Jul 2000
    Posts
    10

    The easyest way!

    Heres the easyest way of rounding numbers in flash

    Set Variable: "number" = INT(number + 0.5 )

    Bests - Timme

  12. #12
    Senior Member
    Join Date
    Jul 2000
    Location
    Not on the dole any more
    Posts
    1,040
    That only rounds up...the title of the thread is a bit misleading, but if you read the question...

    if i type in 5.4 I want to return 5,
    if is 5.9 I want to return 6.

  13. #13
    Junior Member
    Join Date
    Jul 2000
    Posts
    10

    sorry

    Sorry i've vasted your time - here's the way to do it easy:

    number = int( number - 0.5 ) + 1

    Bests - Timme

  14. #14
    Senior Member
    Join Date
    Jul 2000
    Location
    Not on the dole any more
    Posts
    1,040
    Smart -- nice solution.

  15. #15
    Junior Member
    Join Date
    Sep 2000
    Posts
    14

    Thanks everybody....

    Originally posted by Stickman
    Smart -- nice solution.
    Is all done! Thanks for all your help!!!

    John Tubert

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