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
price.ToString(@"#,0.00;-#,0.00;0\,-").Replace(".00", ",-");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With