Bug 15226 - int.ToString() for negative values differs on Android compared to iOS
Summary: int.ToString() for negative values differs on Android compared to iOS
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.8.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2013-10-05 03:17 UTC by Johan Sanneblad
Modified: 2017-08-07 20:36 UTC (History)
2 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 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:

Description Johan Sanneblad 2013-10-05 03:17:18 UTC
I have built an app that communicates with Exchange servers through EWS, for iOS & Android. 

When developing the middleware I noticed there is a bug in int.ToString() for negative values.

Here is an example:

int tzBias = -120;

Android 4.3 (HTC One Google Edition):
tzBias.ToString ());

iOS 7.0 (iPhone 5):
tzBias.ToString ());

If you look closely you will notice that the "-" sign differs on Android versus iOS. They are not the same char.

While they look similar, Exchange servers will reject the output from the Android int.ToString().

Johan Sanneblad
Comment 1 Jonathan Pryor 2013-10-10 14:29:44 UTC
What locale is your device? (See the Settings app.)

int.ToString() (no arguments) uses the current locale (CultureInfo.CurrentCulture) to format values. If your locale is not english/invariant, it may have a different minus sign.

I'm unable to repro:

	int tzBias = -120;
	string s = tzBias.ToString ();
	Console.WriteLine ("{0}={1}", s, 
			string.Join (" ", Encoding.UTF8.GetBytes (s)
				.Select (b => b.ToString ("x2"))));

The above prints:

> I/mono-stdout( 8967): -120=2d 31 32 30

which is clearly a "normal" minus sign.
Comment 2 Johan Sanneblad 2013-10-17 10:36:02 UTC
Hi Jonathan,

I am using Swedish locale on the device.

I was not aware that the locale affected the ASCII value of the minus sign, might be good to put a note on that in the documentation.

Thanks for your reply!

Comment 3 Jon Douglas [MSFT] 2017-08-07 20:36:26 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Android. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.