c# - How can I format currency with no decimals but only when the decimal is zero? -
i using following format decimal currency.
double value = 12345.6789; console.writeline(value.tostring("c", cultureinfo.currentculture)); // result: $12,345.68
which behaviour want, except when decimals 0, in double value = 12345.00;
then result should $12,345
i've tried variations using #
.tostring("c.##"
etc. can't work i'd like.
using decimal
, determine format string use:
//decimal value = 12345.6789m; decimal value = 12345.0000m; var formatstring = decimal.truncate(value) == value ? "c0" : "c"; console.writeline(value.tostring(formatstring, cultureinfo.currentculture));
Comments
Post a Comment