Include the type specifier in your format expression:
>>> a = 10.1234
>>> f'{a:.2f}'
'10.12'
More Related Contents:
- How to postpone/defer the evaluation of f-strings?
- f-strings vs str.format()
- How to escape curly-brackets in f-strings? [duplicate]
- How do I convert a string into an f-string?
- Transform string to f-string
- Nested f-strings
- How can I use newline ‘\n’ in an f-string to format output?
- How can I use f-string with a variable, not with a string literal?
- Checking sum of items in a list if equals target value
- In the last for loop I will to exclude execution of loop when Y=0 is met. How to I do it? [closed]
- TypeError: cannot parse from ‘list’
- What are variable annotations?
- How can I connect to MySQL in Python 3 on Windows?
- ‘str’ object has no attribute ‘decode’. Python 3 error?
- Using multiple Python engines (32Bit/64bit and 2.7/3.5)
- Importing class from another file [duplicate]
- What is the meaning of “Failed building wheel for X” in pip install?
- When should iteritems() be used instead of items()?
- Clear QLineEdit on click event
- How to set the timezone in Django
- Why doesn’t str.translate work in Python 3?
- Understand Python swapping: why is a, b = b, a not always equivalent to b, a = a, b?
- How do you use subprocess.check_output() in Python?
- pip no longer working after update error ‘module’ object is not callable
- What is the correct syntax for ‘else if’?
- Python – Printing a dictionary as a horizontal table with headers
- Switching to Python 3 causing UnicodeDecodeError
- Find Out If a Function has been Called
- RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
- Confusion about pandas copy of slice of dataframe warning