[swift-users] Decimal to Double?

Stephen Canon scanon at apple.com
Mon Nov 28 13:31:42 CST 2016


> On Nov 28, 2016, at 2:29 PM, David Sweeris via swift-users <swift-users at swift.org> wrote:
> 
> Sent from my iPhone
>> On Nov 28, 2016, at 13:21, Joe Groff <jgroff at apple.com> wrote:
>> 
>> It really shouldn't be, since ExpressibleByFloatLiteral uses a binary float initial value and so doesn't guarantee decimal accuracy. I'd recommend using init(mantissa:exponent:isNegative:) instead, and minimizing any conversions between Double and Decimal.
> 
> That's what I was worried about... What's the "correct" way to express a literal as a Decimal, then? Use a string literal, `"2.1"`, instead of a float literal, `2.1`?

Yes. Adding decimal literals would be a nice improvement at some future point, strings are the correct solution until then.


More information about the swift-users mailing list