+ 2
thousand separator for float nums?
#numbers with thousands separator print(format(10000,",d")) print(format(10000.50,",d")) for the second line i get a value error for float nums is there another way to get the output as 10,000.50 https://code.sololearn.com/clRdE90GjCEV/?ref=app
3 ответов
+ 6
print(f'{10000.50:,}')
+ 3
Angela ,
This is a sample that shows the use of format strings with also explanation what the arguments are meaning.
number = 4270.138
print(f"{number:,.2f}")
# Output is: 4,270.14 The output is also rounded to the number of digital places
This is what the arguments in the curly braces are:
`number`: Variable or expression that should be formatted
: (colon): After this the format specs will follow
, (comma): Grouping separator for thousands.
. (dot): Separator for floating point numbers. (decimal point)
2 : Displays 2 decimal places. (precision)
f: Specifies the data format floating-point
+ 3
@sanda
thanks a lot. that helps to understand.