About 614,000 results
Open links in new tab
  1. How to format a floating number to fixed width in Python

    How do I format a floating number to a fixed width with the following requirements: Leading zero if n < 1 Add trailing decimal zero(s) to fill up fixed width Truncate decimal digits past fixed w...

  2. How do I format a number with a variable number of digits in …

    Jul 12, 2010 · With the introduction of f-strings in Python 3.6, it is now possible to access previously defined variables without the need for .format. Simply prepend an f to the string: …

  3. Format numbers to strings in Python - Stack Overflow

    Starting with Python 3.6, formatting in Python can be done using formatted string literals or f-strings: hours, minutes, seconds = 6, 56, 33 f'{hours:02}:{minutes:02}:{seconds:02} {"pm" if …

  4. python - Display number with leading zeros - Stack Overflow

    In Python 2 (and Python 3) you can do: number = 1 print("%02d" % (number,)) Basically % is like printf or sprintf (see docs).

  5. How to print a number using commas as thousands separators

    How do I print an integer with commas as thousands separators? 1234567 1,234,567 It does not need to be locale-specific to decide between periods and commas.

  6. Python formatting integer (fixed digits before/after the decimal …

    Apr 19, 2022 · I was wondering if it's possible to use two format options together when formatting integers. I know I can use the bellow to include zero places varInt = 12 print( "Integer : " + …

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

    Mar 15, 2011 · Given a float between 0 and 1, how to print it as a percentage? For example, 1/3 should print as 33%.

  8. Fixed width number formatting python 3 - Stack Overflow

    Jul 29, 2011 · How do I get an integer to fill 0's to a fixed width in python 3.2 using the format attribute? Example: a = 1 print('{0:3}'.format(a)) gives ' 1' instead of '001' I want. In python 2.x, …

  9. How can I format a decimal to always show 2 decimal places?

    This Stack Overflow page discusses methods to format a decimal number to always display two decimal places in various programming languages.

  10. python - Print Combining Strings and Numbers - Stack Overflow

    Aug 18, 2012 · To print strings and numbers in Python, is there any other way than doing something like: first = 10 second = 20 print "First number is %(first)d and second number is …

Refresh