+ 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

25th Aug 2023, 8:06 AM
Angela
Angela - avatar
3 Respostas
+ 6
print(f'{10000.50:,}')
25th Aug 2023, 8:57 AM
Bob_Li
Bob_Li - avatar
+ 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
25th Aug 2023, 10:51 AM
sandra
sandra - avatar
+ 3
@sanda thanks a lot. that helps to understand.
25th Aug 2023, 12:47 PM
Angela
Angela - avatar