Bug 21764 - Rounded decimal .ToString() produces different results on Mono and .NET
Summary: Rounded decimal .ToString() produces different results on Mono and .NET
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.4.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2014-08-01 09:16 UTC by Andrew
Modified: 2014-08-06 10:25 UTC (History)
2 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 Andrew 2014-08-01 09:16:15 UTC
Consider the following example:

var d1 = decimal.Parse("123");
var d2 = Math.Round(d1, 5);
Console.Out.WriteLine("d1: " + d1.ToString(CultureInfo.InvariantCulture));            
Console.Out.WriteLine("d2: " + d2.ToString(CultureInfo.InvariantCulture));

Output on Windows .NET:

d1: 123
d2: 123

Output on Xamarin (iOs/Android apps):

d1: 123
d2: 123.00000

There're unexpected and meaningless zeros after the dot.
I would expect the same output on both platforms, without the trailing zeros.

In case of float and double, this example works as expected.


Here's my configuration:
=== Xamarin Studio ===

Version 5.1.4 (build 0)
Installation UUID: f2d8ae39-3eb3-46bf-81fc-1fbdf9af5486
Runtime:
	Mono 3.4.0 ((no/954ed3c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000214

=== Xamarin.Android ===

Version: 4.12.6 (Business Edition)
Android SDK: /Users/Andrew/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: 7.2.5.5 (Business Edition)
Hash: 87026b6
Branch: 
Build date: 2014-07-02 19:39:08-0400

=== Xamarin.Mac ===

Version:

=== Build Information ===

Release ID: 501040000
Git revision: 7d45bbe2ee22625f125d0c52548524f02d005cca
Build date: 2014-07-14 12:15:53-04
Xamarin addins: c78f1d88e57baa928aeee1484d96e6f8edf8de33

=== Operating System ===

Mac OS X 10.9.4
Darwin Andrews-MacBook-Pro.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 1 marcos.henrich 2014-08-05 09:06:52 UTC
Hi Andrew,

Thanks for the bug report.
The pull request for this issue can be found in the link below.
https://github.com/mono/mono/pull/1193
Comment 2 marcos.henrich 2014-08-06 10:25:22 UTC
Fixed in master e003c4e8f9e5ffef89a7527595c94d7457abe1a6.