Round decimal up in Python

1

I have a decimal number of 1.1 or 1.2 or 1.6 or 1.9 what I want is to approximate any of these numbers to 2.

I mean I have a 1.1. How do I approach 2? By means of int() all approaches to 1, the same if I have 3.4 or a 3.1 or 3.8 approaches them to 3. How to approximate to 4 and so for other numbers?

    
asked by Yeison Ordoñez 26.04.2016 в 18:14
source

1 answer

2

You can use the function ceil of the module math (which rounds to up ) or the function floor (which rounds to below )

import math
math.ceil(1.1)
math.ceil(1.2)
math.ceil(1.6)
math.ceil(1.9)

Exit:

2
2
2
2

For more information:

link

    
answered by 26.04.2016 / 18:17
source