-2

I'm getting a number in my software and I would like to apply a process if this number is a decimal number.

I would like to round my number to the upper entire number.

For example :

Get number --> expected
1.3 --> 2
1.7 --> 2
2.0 --> 2
2.1 --> 3

Is it possible to create something like this ? I'm looking for splitting function :

x = 3.4
x1 = int(round(x))
returns : 3 and not 4

Thank you by advance, I'm looking if I don't find a solution to my issue.

Shashank Singh
  • 647
  • 1
  • 5
  • 22
Essex
  • 6,042
  • 11
  • 67
  • 139
  • https://stackoverflow.com/questions/4518641/how-to-round-a-floating-point-number-up-to-certain-decimal-place – rishat Feb 19 '18 at 09:41
  • Use `if type(x) == 'float':` – Anup Yadav Feb 19 '18 at 09:41
  • 2
    Possible duplicate of [How to round a floating point number up to certain decimal place?](https://stackoverflow.com/questions/4518641/how-to-round-a-floating-point-number-up-to-certain-decimal-place) – rishat Feb 19 '18 at 09:41
  • `math.ceil(decimal.Decimal('3.5'))`, or something along those lines, depending on what your input is exactly and what accuracy you want. – deceze Feb 19 '18 at 09:41
  • @RishatMuhametshin It's not what I want. Look what I've done, it's the same thing, but it doesn't return what I would like to get. – Essex Feb 19 '18 at 09:41
  • 4
    `round` isn't the term you are looking for. It is `ceil`. – Lafexlos Feb 19 '18 at 09:43

2 Answers2

3

Use this:

import math
math.ceil(<decimal>)

Example :

>>> import math
>>> math.ceil(1.3)
2
>>> math.ceil(1.7)
2
>>> math.ceil(2.0)
2
>>> math.ceil(2.1)
3
Shashank Singh
  • 647
  • 1
  • 5
  • 22
-2

Hello the method that you want it´s round

a = 1
b = 2

c = round(b/a)
print(c)
>>>> 0
  • `round()` rounds off the value to the closest integer where as `ceil()` always rounds it off to the higher integer. As `round(1.3)` is `1` and `round(1.7)` is `2` but `math.ceil(1.3)` is `2` and `math.ceil(1.7)` is also `2`. – Shashank Singh Feb 19 '18 at 10:07