Reputation: 1271
I want to string format a double value - a product price - with two decimals when the price is eg. 12.99, and with a ",-" when the price is 12.00. Is that possible using the ToString() extension in C# .NET?
I have tried
price.ToString(@"#,0.00;-#,0.00;0\,-");
and this 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 statement to separate positive, negative and zero numbers.
Can this be done without doing if/else logic in the code?
Cheers Jens
Upvotes: 3
Views: 391