How to format a double value as an unsigned currency price and with a special case without decimal places

I want the string format to have a double meaning - the price of the product - with two decimal places when the price, for example. 12.99, and with ", -" when the price is 12.00. Is it possible to use the ToString () extension in C # .NET?

I tried

price.ToString(@"#,0.00;-#,0.00;0\,-");

      

and that gives me "12.99" just fine. But 12.00 shows as "12.00" and I would prefer it to be "12, -". I use groups in the above description to separate positive, negative and zero numbers.

Is it possible to do this without executing if / else logic in the code?

Cheers Jens

+3


source to share


1 answer


price.ToString(@"#,0.00;-#,0.00;0\,-").Replace(".00", ",-");

      



+1


source







All Articles