Does anyone know how I can get a format string to use bankers rounding? I have been using "{0:c}" but that doesn't round the same way that bankers rounding does. The Math.Round()
method does bankers rounding. I just need to be able to duplicate how it rounds using a format string.
Note: the original question was rather misleading, and answers mentioning regex derive from that.
Can't you simply call Math.Round() on the string input to get the behavior you want?
Instead of:
string s = string.Format("{0:c}", 12345.6789);
Do:
string s = string.Format("{0:c}", Math.Round(12345.6789));
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