-3

This is my code so far:

number = 201234
print(f'number is {number:,.0f}')

This prints: number is 201,234

However I want it to print: number is 200,000

I've tried using print(f'number is {number:,.1g}') but this prints in scientific notation like so: number is 2e+05

Is there a simple way to format this to get the desired outcome?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61

1 Answers1

1

Use the round() function with a negative argument.

number = 201234
print(f'number is {round(number, -5):,.0f}')

Prints

number is 200,000
Ross MacArthur
  • 4,735
  • 1
  • 24
  • 36
  • 2
    The accepted answer in the linked duplicate already covers this. Please don't answer duplicate questions. Instead, flag this one / vote to close as a duplicate. – Pranav Hosangadi Oct 06 '20 at 15:08
  • This is not a duplicate question, I wanted to know if it's possible to do this with f-strings and without using round. – Michael Gomes Vieira Oct 07 '20 at 09:36