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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -