c# - Special decimal formatting -
is there string format can used on decimal following results obtained?
123 => "123" 123.4 => "123.40" 123.45 => "123.45" 123.456 => "123.46"
in english, number should displayed 2 decimals, except when holds integer value, when should have no decimals (so no "123.00" displays allowed).
i don't know of such format, i'm afraid. might need use:
string text = (d == (int) d) ? ((int) d).tostring() : d.tostring("n2");
edit: code above work when d
in range between int.minvalue
, int.maxvalue
. can better using long
, if want cover full range of decimal
you'll need little more powerful.
Comments
Post a Comment