Bug 6444 - decimal.ToString() on zero values (e.g., 0.000m) behavior differs from csc
Summary: decimal.ToString() on zero values (e.g., 0.000m) behavior differs from csc
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2012-08-07 10:55 UTC by cod3monk3y
Modified: 2013-03-31 04:07 UTC (History)
1 user (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 cod3monk3y 2012-08-07 10:55:52 UTC
A decimal zero with multiple digits of precision (e.g "0.0m", "0.00m") should convert to string with the same precision as originally specified (according to csc), but mcs always returns "0". This behavior occurs both with decimal.Parse("0.0").ToString() as well as the literal 0.0m.ToString().

Non-zero values with multiple zero digits of precision (e.g. "1.000") appear to work properly. 

// Expected Output (csc):
//      0
//      0.0
//      0.00
//      0.000
//      1.000
//
// Actual Output (mcs):
//      0
//      0
//      0
//      0
//      1.000
//
Trace.WriteLine(decimal.Parse("0").ToString());
Trace.WriteLine(decimal.Parse("0.0").ToString());
Trace.WriteLine(decimal.Parse("0.00").ToString());
Trace.WriteLine(0.000m.ToString());
Trace.WriteLine(1.000m.ToString());
Comment 1 Marek Safar 2012-08-08 06:27:12 UTC
Fixed in master
Comment 2 cod3monk3y 2013-03-30 13:58:27 UTC
Hi Marek. I see this fixed in the github repository main branch:
https://github.com/mono/mono/commits/225b47efbdb125ef99512a5a577c3034fb6de79c/mono/metadata/decimal.c

I apologize for my ignorance on the mono pipeline. But when can I expect to see this version in an official release? 

I'm using Xamarin Studio with Mono 2.10.12, and the git branch for mono-2-10 doesn't have the fix, and the code still outputs "0" for "decimal.Parse("0.00").ToString(). 

Here are my details from Xamarin Studio About:

Xamarin Studio
Version 4.0.3 (build 13)
Installation UUID: c26858de-4307-46b9-9b68-5d27be3d7784
Runtime:
	Mono 2.10.12 (mono-2-10/c9b270d)
	GTK 2.24.16
	GTK# (2.12.0.0)
	Package version: 210120000

Thanks for the fix! I'd just like to use it in my code! (Note: I'm setting this to REOPENED because I'm not sure if you'll get notification if I only add a comment).
Comment 3 Marek Safar 2013-03-31 04:07:06 UTC
You need to download Mono 3.0