Bug 20246 - float to NSDecimal casting doesn't work
Summary: float to NSDecimal casting doesn't work
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 7.2.3
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2014-06-01 08:23 UTC by Michal Blaha
Modified: 2014-06-01 20:43 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 Michal Blaha 2014-06-01 08:23:49 UTC
Version: mtouch (fc6f56b)

float f = 0.7f;
NSDecimal d = (NSDecimal)f; // bug => 0
NSDecimal d1 = (NSDecimal)(0.7f); // bug => 0
NSDecimal d = (NSDecimal)(0.7m); // bug => 0
NSDecimal d = (NSDecimal)(0.7); // bug => 0

NSDecimal d = (NSDecimal)(1f); // OK => 1
NSDecimal d = (NSDecimal)(1.1f); // bug => 1


NSDecimal d = new NSDecimalNumber("0.7").NSDecimalValue ;
Comment 1 Sebastien Pouliot 2014-06-01 19:38:21 UTC
The issue is that the only operator currently defined is for Int32 - which means your float/double/decimal are turned into integers before becoming NSDecimal. I'll look into why...
Comment 2 Sebastien Pouliot 2014-06-01 20:43:13 UTC
Fixed* in master 8b3b7d6f9a20f576e16271878c5ed687f2c5c375

* added missing operators for float/double/decimal