About 103,000 results
Open links in new tab
  1. How to round to 2 decimals with Python? [duplicate]

    Dec 9, 2013 · Assuming your intent is to do the traditional rounding for statistics in the sciences, this is a handy wrapper to get the round function working as expected needing to import extra …

  2. python - round a single column in pandas - Stack Overflow

    Oct 1, 2014 · .round() is a pandas method and it applies to the output format rather than the underlying value. If you have floats with many decimal places you can instead apply the …

  3. python - How do you round UP a number? - Stack Overflow

    May 5, 2017 · If the number has decimal part: round_up - round_down == 1, always. If the number doens't have decimal part: round_up - round_down == 0. So: round_up == x + …

  4. Python 3.x rounding behavior - Stack Overflow

    May 31, 2012 · I was just re-reading What’s New In Python 3.0 and it states: The round() function rounding strategy and return type have changed. Exact halfway cases are now rounded to the …

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

    Jan 22, 2015 · Here is a simple function to do this for you: def precision(num,x): return "{0:.xf}".format(round(num)) Here, num is the decimal number. x is the decimal up to where …

  6. round () doesn't seem to be rounding properly - Stack Overflow

    That would only work if the rounding were consistently off from the round number by epsilon. If epsilon = .000001 then round(1.0/5.0, 1) + epsilon would take the precise representation 0.2 …

  7. How to round each item in a list of floats to 2 decimal places?

    I came to this stackoverflow page looking for a function to round a list of 2D coordinates. Here are two ways to do that similar to the answer provided by Wilson using numpy. Notice that the first …

  8. python - How to properly round-up half float numbers? - Stack …

    @simomo Python's round() function used to round up in older versions, but they switched the rounding strategy to half to even in Python 3. It was a deliberate choice because this produces …

  9. How to round a number to significant figures in Python

    So a function to round x to 1 significant figure is the following: import math def round_1sig(x): if x == 0: return x return round(x, -math.floor(math.log10(abs(x)))) And more generally, a function …

  10. Rounding decimals with new Python format function

    Nov 9, 2011 · Here's a typical, useful example...: >>> n = 4 >>> p = math.pi >>> '{0:.{1}f}'.format(p, n) '3.1416' the nested {1} takes the second argument, the current value of n, …

Refresh