Top "String-formatting" questions

Commonly refers to a number of methods to display an arbitrary number of varied data types into a string.

String formatting: % vs. .format vs. string literal

Python 2.6 introduced the str.format() method with a slightly different syntax from the existing % operator. Which is better and for …

python performance logging string-formatting f-string
Display number with leading zeros

Given: a = 1 b = 10 c = 100 How do I display a leading zero for all numbers with less than two digits? This …

python integer string-formatting
Using String Format to show decimal up to 2 places or simple integer

I have got a price field to display which sometimes can be either 100 or 100.99 or 100.9, What I want is to …

c# regex string-formatting number-formatting
How can I fill out a Python string with spaces?

I want to fill out a string with spaces. I know that the following works for zero's: >>> …

python string string-formatting pad
How can I print literal curly-brace characters in python string and also use .format on it?

x = " \{ Hello \} {0} " print(x.format(42)) gives me : Key Error: Hello\\ I want to print the output: {Hello} 42

python string format string-formatting curly-braces
How can I format a decimal to always show 2 decimal places?

I want to display: 49 as 49.00 and: 54.9 as 54.90 Regardless of the length of the decimal or whether there are are any …

python string-formatting
Best way to format integer as string with leading zeros?

I need to add leading zeros to integer to make a string with defined quantity of digits ($cnt). What the …

python string-formatting
Format a datetime into a string with milliseconds

I want to have a datetime string from the date with milliseconds. This code is typical for me and I'm …

python datetime string-formatting
Formatting Numbers by padding with leading zeros in SQL Server

We have an old SQL table that was used by SQL Server 2000 for close to 10 years. In it, our employee …

sql sql-server tsql string-formatting