Thursday, December 3, 2026 | London 10°C · Drizzle
DailyGlimpse

AI

Python f-string Trick: Convert Floats to Percentages Instantly

CodingWithMee 1 min read

Want to turn a floating-point number into a clean percentage in Python? Use f-strings with the :.2% format specifier. For example:

x = .023
print(f'{x:.2%}')

Output: 2.30%

This automatically multiplies the number by 100, rounds to two decimal places, and appends the percent sign. It's a handy trick for data science, machine learning, analytics, and any Python project requiring polished output.

React