I want a function that shows at most N decimal places, but does not pad 0's if it is unnecessary, so if N = 2,
2.03456 => 2.03
2.03 => 2.03
2.1 => 2.1
2 => 2
Every string formatting thing I have seen will pad values like 2 to 2.00, which I don't want
How about this:
// max. two decimal places
String.Format("{0:0.##}", 123.4567); // "123.46"
String.Format("{0:0.##}", 123.4); // "123.4"
String.Format("{0:0.##}", 123.0); // "123"
Try this:
string s = String.Format("{0:0.##}", value);
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