[swift-users] Decimal to Double?

Philippe Hausler phausler at apple.com
Mon Nov 28 09:48:55 CST 2016


This might be a bit nicer since that is relying on NSNumber bridges. You can bridge to NSDecimalNumber directly like this: 

(Decimal(1.0) as NSDecimalNumber).doubleValue

(but perhaps we should consider adding initializers that follow the same pattern as Double that don’t have to bridge to solve the problem)

> On Nov 28, 2016, at 2:40 AM, Alex Blewitt via swift-users <swift-users at swift.org> wrote:
> 
> You can wrap it with an NSDecimalNumber, and then cast it to a Double from there:
> 
> Double(NSDecimalNumber(decimal:Decimal(1.0)))
> 
> Alex
> 
>> On 28 Nov 2016, at 10:13, Rick Mann via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>> 
>> How do I get a Double from a Decimal?
>> 
>> TIA,
>> 
>> -- 
>> Rick Mann
>> rmann at latencyzero.com <mailto:rmann at latencyzero.com>
>> 
>> 
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161128/86d11f21/attachment.html>


More information about the swift-users mailing list