About 168,000 results
Open links in new tab
  1. Python Decimals format - Stack Overflow

    Mar 6, 2010 · Python Format Decimal with a minimum number of Decimal Places. 2. Having trouble formatting my decimals. 1

  2. python - How can I format a decimal to always show 2 decimal …

    I suppose it might mean that the OP is using decimal.Decimal and is unhappy with decimal context's precision which limits precision to n digits as in "n digits of precision in the strict sense" (e.g. '123.456' becomes Decimal('1.2E+2')) and not "n digits in the fractional part" (for Decimal('123.45'))...

  3. python - Limiting floats to two decimal points - Stack Overflow

    Jan 19, 2009 · Learn how to limit floats to two decimal points in Python on Stack Overflow.

  4. python - How to display a float with two decimal places ... - Stack ...

    I have a function taking float arguments (generally integers or decimals with one significant digit), and I need to output the values in a string with two decimal places (5 → 5.00, 5.5 → 5.50, etc)...

  5. Rounding decimals with new Python format function

    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, and applies it as specified (here, to the "precision" part of the format -- number of digits after the decimal point), and the outer resulting {0:.4f} then applies.

  6. How to format a floating number to fixed width in Python

    The format specifier inside the curly braces follows the Python format string syntax. Specifically, in this case, it consists of the following parts: The empty string before the colon means "take the next provided argument to format()" – in this case the x as the only argument. The 10.4f part after the colon is the format specification.

  7. python - Display a decimal in scientific notation - Stack Overflow

    Aug 2, 2011 · As an aside, despite the format % values syntax still being used even within the Python 3 standard library, I believe it's technically deprecated in Python 3, or at least not the recommended formatting method, and the current recommended syntax, starting with Python 2.6, would be '{0:.2E}'.format(Decimal('40800000000.00000000000000')) (or '{:.2E}' in Python 2.7+).

  8. python - How to print a percentage value? - Stack Overflow

    Mar 15, 2011 · Percentage. Multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign. The .0 part of the format spec .0% indicates that you want zero digits of precision after the decimal point, because with f"{1/3:%}" you would get the string '33.333333%'. It works with integers, floats, and decimals. See PEP 3101.

  9. Format Python Decimal object to a specified precision

    Jan 25, 2017 · decimal.Decimal supports the same format specifications as floats do, so you can use exponent, fixed point, general, number or percentage formatting as needed. This is the official and pythonic method of formatting decimals; the Decimal class implements the .__format__() method to handle such formatting efficiently.

  10. How can I locale-format a python Decimal and preserve its …

    Aug 10, 2015 · Format Python Decimal object to a specified precision. 1. Precision of decimals in Python. 4. python ...

Refresh