Bug 51692 - Method decimal.Parse() has different behavior on .net 4.6 x86 and adnroid x86 mono
Summary: Method decimal.Parse() has different behavior on .net 4.6 x86 and adnroid x86...
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 4.6.0 (C8)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2017-01-22 20:23 UTC by Sergey
Modified: 2017-01-23 08:31 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Sergey 2017-01-22 20:23:42 UTC
Windows 8.1. Visual Studio 2015 Update 3. 

The result on the Windows .NET 4.6 platform:

// Result = 0.0123
var result2 = decimal.Parse("0,0123");

// There is an exception FormatException.
var result1 = decimal.Parse("0.0123");

The result on the Android Emulator x86:

// Result = 0.0123. The dot is allowed
var result2 = decimal.Parse("0.0123");

// No exceptions. Result = 123
var result1 = decimal.Parse("0,0123");

See example code on github:
Comment 1 Sergey 2017-01-22 20:47:53 UTC
It turned out that it was an bug on x86 (which is reproduced on the simulator android). On a real device ARM's all good.
Comment 2 Marek Habersack 2017-01-23 08:23:26 UTC
@Sergey, number parsing is dependent on the locale/culture settings on the given machine, device. As such, this behavior is not a bug - the environment you run in may indicate that a dot is a valid decimal separator along with the comma. Yet another environment, even for the same culture, may have different locale/cultural settings that prevent using the dot or the comma in the same situation. In general, when parsing decimals it is advised to first try parsing using the current culture, whatever it is, especially when the input comes from the user and then fall back to the known/possibly valid culture(s). Also, using `TryParse` is advisable.
Comment 3 Sergey 2017-01-23 08:31:16 UTC
@Marek, thank you.