1

Are there any cultures where num.ToString("D") will use something other than the regular minus sign ("\u002D") for negative numbers?

Documentation for Decimal format specifier (D) states the formatted string is affected by the current NumberFormatInfo object. Specifically by the NumberFormatInfo.NegativeSign property.

Documentation for NumberFormatInfo.NegativeSign states

The string that denotes that the associated number is negative. The default for InvariantInfo is "-".

but does not give any examples of what this value may be in any cultures other than InvarianCulture.

I need to always have the regular minus sign ("\u002D") for negative numbers, regardless of the current culture. An obvious way to achieve this is to use num.ToString("D", CultureInfo.InvariantCulture).

Unfortunately we already have code in production that uses num.ToString("D"), so I am trying to find out whether it may produce something other than the regular minus sign in some culture.

George
  • 2,436
  • 4
  • 15
  • 30
  • 1
    Given that the `CultureInfo` class provides the means to get all cultures, you can simply look for yourself. – jmcilhinney Sep 28 '22 at 16:40
  • @jmcilhinney I can get all cultures on my system. this is a crossplatform app. I don't know if an iPhone in another country will have the same list of cultures. – George Sep 28 '22 at 16:42
  • Since the documentation does not guarantee that the negative sign will always be 0x2D, i'd suggest you clone the [appication-wide current culture](https://stackoverflow.com/a/13367456/19858830) or current main thread culture at the very start of the program, explicitly set the the negative sign in the cloned culture, and make the cloned culture the default current culture of your application. Caveat: If your program changes the current culture to some other during its execution, this simple trick won't work, obviously. –  Sep 28 '22 at 17:04

0 Answers0