Bug 44385 - double.TryParse fails to parse "9.5" if iOS version is 9.1 or 9.0
Summary: double.TryParse fails to parse "9.5" if iOS version is 9.1 or 9.0
Status: CLOSED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: XI 10.0 (iOS10)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL: https://github.com/baskren/decimalparse
Depends on:
Blocks:
 
Reported: 2016-09-15 19:12 UTC by Ben Askren
Modified: 2016-09-15 21:12 UTC (History)
5 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 Developer Community or GitHub 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:
CLOSED ANSWERED

Description Ben Askren 2016-09-15 19:12:38 UTC
Just upgraded Xamarin Studio to 6.1 (build 5441).  Details:

Xamarin Studio Business
Version 6.1 (build 5441)
Installation UUID: 15f7ff53-c1aa-4b06-8d01-b07bc058bf31
Runtime:
	Mono 4.6.0 (mono-4.6.0-branch/746756c) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406000245

NuGet
Version: 3.4.3.0

Xamarin.Profiler
Version: 0.33.2
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Apple Developer Tools
Xcode 8.0 (11246)
Build 8A218a

Xamarin.Mac
Not Installed

Xamarin.iOS
Version: 10.0.0.6 (Xamarin Business)
Hash: 6c3fee4
Branch: xcode8
Build date: 2016-09-09 13:01:32-0400

Xamarin.Android
Version: 7.0.0.18 (Xamarin Business)
Android SDK: /Users/ben/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.1 (API level 16)
		4.2 (API level 17)
		4.3 (API level 18)
		4.4 (API level 19)
		5.0 (API level 21)
		5.1 (API level 22)
		6.0 (API level 23)
		7.0 (API level 24)

Now my iOS Xamarin.Forms iOS applications fail to perform a double.TryParse (in iOS versions 9.0 and 9.1) if the string to be parsed contains a decimal point.  This issue is not present in iOS 10.  A sample project can be found at https://github.com/baskren/decimalparse.  

Code excerpt:

using System;
using Xamarin.Forms;

namespace decimalparse
{
	public class App : Application
	{
		public App()
		{
			double result;
			string input = "9.5";
			string status = "Success";
			if (!double.TryParse(input, out result))
				status = "Fail!";
			
			var content = new ContentPage
			{
				Title = "decimalparse",
				Content = new StackLayout
				{
					Children = {
					new Label { Text = "the result of double.TryParse(\"9.5\",out result); is ..." },
					new Label { Text = status }
					}
				}
			};

			MainPage = new NavigationPage(content);
		}

	}
}
Comment 1 Sebastien Pouliot 2016-09-15 19:48:51 UTC
`double.TryParse` works on the current culture of the device. It sounds like your simulator (or devices) are using a different culture.

Where I am (Canada) the code would fail as a comma should be used, e.g. "9,5" would be valid.

The API has overloads that you can use if the data is not-culture aware (e.g. from a file where the format mandates a `.`).
Comment 2 Ben Askren 2016-09-15 21:12:57 UTC
Sebastien -

Thank you.  Your response was very helpful.

- Ben