I read a lot of articles about number format string, ex: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
I really not understand how to write the best format string. To get a excepted result, I can write some ways. Example: print number 1234567890 as a text "1,234,567,890". These ways give the same result:
1234567890.ToString("#,#")
1234567890.ToString("#,##")
"#,##" is the popular one on internet but why? Please give me some information how to write a good format string. Thanks.
%s acts as a placeholder for the real value. You place the real value after the % operator. This method is often referred to as the "older" way because Python 3 introduced str. format() and formatted string literals (f-strings).
A format of . 2f (note the f ) means to display the number with two digits after the decimal point. So the number 1 would display as 1.00 and the number 1.5555 would display as 1.56 . A program can also specify a field width character: x = 0.1.
As far as I can see, there is no difference between "#,#"
and "#,##"
: both mean 'format a number with group separators and without the fractional part'. Refer to SSCLI source for general number formatting for the gory details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With