Convert strings to numeric and group delimiter

When I try to convert a string to a numeric value using Parse or TryParse or Convert.ChangeType, I cannot control the thousands separator as it is defined on the system:

if I enter:

var d = double.Parse("1,234", CultureInfo.CurrentUICulture);

it does not return 1234.

If I want to use the group separator, I must enter:

var d = double.Parse("1,234", NumberStyles.Number, CultureInfo.CurrentUICulture);

This time the result is as follows:

But I do not want to use the thousandth separator, I want to use it only if the system sets it in the globalization settings. Is there a way to find out if a separator is being used (I know that I can read the group separator in CultureInfo.CurrentUICulture.NumberFormat.NumberGroupSeparator)

Cheers Loic

+5
source share
3 answers

Number ( AllowThousands), - . , Number . Any AllowThousands.

, "" " ", .. Eurupe ( ..). " - ", (, InvariantCulture).

+2

,

var d = double.Parse("1,234", NumberStyles.Number, CultureInfo.CurrentUICulture);

1234, 1234, 1.234 , ".".

0

, CurrentCulture, CurrentUICulture.

The property CurrentUICulturerefers to the language in which the user interface is displayed, and CurrentCultureto the current language specified in Windows. Thus, a user working with an application that provides a user interface translated into English ( CurrentUICulture) can still view / enter, for example, dates and numbers formatted as the locale installed in Windows ( CurrentCulture).

0
source

All Articles