A Flash Developer Resource Site

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

1. 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. 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. ## 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. ## 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. ## 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. ## 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. 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. 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. 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. ## Very Nice!

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

11. ## The easyest way!

Heres the easyest way of rounding numbers in flash

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

Bests - Timme

12. 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. ## sorry

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

number = int( number - 0.5 ) + 1

Bests - Timme

14. Smart -- nice solution.

15. ## 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
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap