.net - Format Numeric Strings -
i want format integer appears 1000's separator (,)
my attempts far have been:
string.format("{0:#,###.##}", 1234.0); // 1,234 string.format("{0:#,###.##}", 1234.05); // 1,234.05 string.format("{0:#,###.##}", 1234); // 1,234
i struggling display values output 1,234.0.. please suggest me how output string 1,234.0 ??
the way understand question:
- you want thousand separator every 3 digits on integer side
- you want 1 digit on fractional side
additionally, guess that
- you want @ least 1 digit on integer side
the problem format strings you're using you're using #
specify digit positions. according documentation, character means:
replaces "#" symbol corresponding digit if 1 present; otherwise, no digit appears in result string.
(my emphasis)
on other hand, 0
character:
replaces 0 corresponding digit if 1 present; otherwise, 0 appears in result string.
(again, emphasis)
so should use 0
's instead of #
's.
specifically, here format string use according 3 bulletpoints @ top of answer:
#,##0.0
this means:
- comma means "add thousand separator"
- the
#,##0
means "set aside place integer part here, add thousand separator if necessary, , add digits after first if necessary, add @ least 1 digit, don't.1
result" .0
means "1 fractional digit"- your
.#
mean "add decimal point , fractional digit if fractional digit other 0, if 0, don't add either", that's main problem formatting strings
- your
here's .net fiddle try with.
Comments
Post a Comment