c# - .NET currency formatter: can I specify the use of banker's rounding? - TagMerge
3.NET currency formatter: can I specify the use of banker's rounding?.NET currency formatter: can I specify the use of banker's rounding?

.NET currency formatter: can I specify the use of banker's rounding?

Asked 1 years ago
4
3 answers

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));

Source: link

3

Regexp is a pattern matching language. You can't do arithmetic operations in Regexp.

Do some experiements with IFormatProvider and ICustomFormatter. Here is a link might point you in the right direction. http://codebetter.com/blogs/david.hayden/archive/2006/03/12/140732.aspx

Source: link

0

Its not possible, a regular expression doesn't have any concept of "numbers". You could use a match evaluator but you'd be adding imperative c# code, and would stray from your regex only requirement.

Source: link

Recent Questions on c#

    Programming Languages