Bug 8084 - Incorrect number parsing because wrong locale or number format settings
Summary: Incorrect number parsing because wrong locale or number format settings
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2012-10-30 18:31 UTC by Eddy Zavaleta
Modified: 2013-04-11 08:29 UTC (History)
3 users (show)

Tags:
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:
Status:
RESOLVED FIXED

Description Eddy Zavaleta 2012-10-30 18:31:41 UTC
Hi,

I have just noticed a wrong behavior in number format using Mono 3.0 on Mac OS X.
I have mexican locale settings: number separators are "." for decimal and "," for thousands.
And mono uses it backwards (or ignore it and uses others settings).

Let's see the following program.

// Test.cs
using System;

class Test
{
	public static void Main (string[] args)
	{
		string str = "2.2";
		decimal num = 2.2m;

		Console.WriteLine ("string: {0}", str);
		Console.WriteLine ("decimal.Parse: {0}", decimal.Parse(str));
		Console.WriteLine ("decimal: {0}", num);
	}
}

Mono 2.10.9 Output:
string: 2.2
decimal.Parse: 2.2
decimal: 2.2

Mono 3.0 Output:
string: 2.2
decimal.Parse: 22
decimal: 2,2

As mono 2.10.9 returns expected results it seems like a regression.
Comment 1 Marek Safar 2012-11-11 13:06:39 UTC
I cannot reproduce the issue.

My repro is here

using System;
using System.Reflection;
using System.Globalization;

namespace Demo
{
	class Test
	{
		public static void Main()
		{
			var ci = new CultureInfo("es-MX");
			System.Threading.Thread.CurrentThread.CurrentCulture = ci;

			string str = "2.2";
			decimal num = 2.2m;

			Console.WriteLine ("string: {0}", str);
			Console.WriteLine ("decimal.Parse: {0}", decimal.Parse(str));
			Console.WriteLine ("decimal: {0}", num);
			return;
		}
	}
}
Comment 2 Eddy Zavaleta 2012-11-12 12:28:55 UTC
I've got same results using your test.

$ mono Demo.exe
string: 2.2
decimal.Parse: 22
decimal: 2,2

I'm using OS X 10.8.2 (12C60) and latest mono release (3.0.1).

$ uname -a
Darwin micteka.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64
$ mono --version
Mono JIT compiler version 3.0.1 (master/301b6c6 Mon Nov  5 14:45:52 EST 2012)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          yes(3.1svn-mono)
	GC:            Included Boehm (with typed GC)
Comment 3 Marek Safar 2012-11-14 10:15:34 UTC
Input CLDR data seems to be buggy in this case
Comment 4 Marek Safar 2012-11-14 10:15:52 UTC
.
Comment 5 DesDesDes 2013-03-19 08:39:46 UTC
Also tested it on windows using mono 3.0.6 and microsoft .net. Used repro from Marek Safar.

Microsoft.net on windows
string: 2.2
decimal.Parse: 2.2
decimal: 2.2

mono 3.0.6 on windows
string: 2.2
decimal.Parse: 22
decimal: 2,2
Comment 6 Marek Safar 2013-03-26 14:20:28 UTC
Fixed in master
Comment 7 DesDesDes 2013-04-11 08:29:07 UTC
Tested on mono 3.0.9. Still the same difference between mono and microsoft .net.