1. First Cup of Ubuntu
Join Date
Jan 2011
Beans
10

## Python Rounding

So, i need to round a number, but the number can't be a decimal number.
So it can't be fx 40.0, it must be 40
And it's rounding to a precision of 1, so 40.1 would be rounded to 40.

2. ## Re: Python Rounding

I would use the round function and then cast the result as an int.

3. First Cup of Ubuntu
Join Date
Jan 2011
Beans
10

## Re: Python Rounding

I tried, but it didn't work in this case of some reason. Well, it worked, but not fully.
Trying to find out if the problem is something else, which is what I really DON'T hope.

4. ## Re: Python Rounding

Originally Posted by noodleman999
Well, it worked, but not fully.
Cana you elaborate on that (input and expected/effective results)? And what is your definition of "round"?

5. First Cup of Ubuntu
Join Date
Jan 2011
Beans
10

## Re: Python Rounding

Okay, i'm currently making a PyGame program, and i want the background to slowly change from black to green, and back.
Therefore, i can't use +1, as it goes too quick
I need to use 0.1
But the pygame.Color function can't take decimals.
After that, i tried:
Code:
```rgc = round(rgc)
rgc = int(rgc)```
And it went to green, fine. But as soon as it tried backwards: Error saying invalid color arguement.

6. ## Re: Python Rounding

Without seeing the code, I can't tell what in particular is wrong with, but your approach seems to use floats needlessly. It seems better to use integers throughout, for example only incrementing the color value every 10 passes of the loop.

7. First Cup of Ubuntu
Join Date
Jan 2011
Beans
10

## Re: Python Rounding

Originally Posted by JDShu
Without seeing the code, I can't tell what in particular is wrong with, but your approach seems to use floats needlessly. It seems better to use integers throughout, for example only incrementing the color value every 10 passes of the loop.
I'll try. Thanks for the tip

#### Posting Permissions

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