About 124,000 results
Open links in new tab
  1. python - How do you round UP a number? - Stack Overflow

    May 5, 2017 · int() always truncates the decimal numbers if a floating number is given; whereas round(), in case of 2.5 where 2 and 3 are both within equal distance from 2.5, Python returns …

  2. How to round to 2 decimals with Python? - Stack Overflow

    Dec 9, 2013 · # Make sure the number is a float a = 2324.55555 # Round it according to your needs # dPoints is the decimals after the point dPoints = 2 # this will round the float to 2 digits …

  3. python - Round number to nearest integer - Stack Overflow

    I've been trying to round long float numbers like: 32.268907563; 32.268907563; 31.2396694215; 33.6206896552; ...

  4. Round up to Second Decimal Place in Python - Stack Overflow

    How can I round up a number to the second decimal place in python? For example: 0.022499999999999999 Should round up to 0.03. 0.1111111111111000 Should round up to …

  5. python - Getting only 1 decimal place - Stack Overflow

    May 16, 2020 · There's also a zero in front that is not necessary. I also think that nobody really understands the format language so keeping it simple is preferred IMO. Now with Python 3.6 I …

  6. Round to 5 (or other number) in Python - Stack Overflow

    Jul 7, 2021 · I don't know of a standard function in Python, but this works for me: Python 3 def myround(x, base=5): return base * round(x/base) It is easy to see why the above works. You …

  7. python - How to round numbers to the nearest 1000 ... - Stack …

    Sep 29, 2017 · A minor warning since it surprises people: Python 3's round uses round-half-even rounding (also known as banker's rounding), and you're more likely to see "halves" when …

  8. rounding - Python - round up to the nearest ten - Stack Overflow

    Oct 20, 2014 · Python 3 (the only difference is you no longer need to cast the result as an int) import math def roundup(x): return math.ceil(x / 10.0) * 10 To use just do

  9. python - How to round a floating point number up to a certain …

    Jan 22, 2015 · def precision(num,x): return "{0:.xf}".format(round(num)) Here, num is the decimal number. x is the decimal up to where you want to round a floating number. The advantage …

  10. Rounding decimals with new Python format function

    Nov 9, 2011 · the nested {1} takes the second argument, the current value of n, and applies it as specified (here, to the "precision" part of the format -- number of digits after the decimal point), …

Refresh