(but perhaps we should consider adding initializers that follow the same pattern as Double that don’t have to bridge to solve the problem)ĭouble(NSDecimalNumber(decimal:Decimal(1. On Nov 28, 2016, at 09:48, Philippe Hausler via swift-users wrote: Once you have an NSDecimalNumber variable, though, I don't know of any better way than that '.doubleValue' property you and Alex mentioned. Swift-users mailing mailing NSDecimalNumber conform to the floating point literal whosywhatsit protocol? If not, wouldn't both of those examples just covert a Double to a decimal and back again? Would there be a purpose to that? Like maybe it'd get rounded differently or something? On, at 10:13, Rick Mann via swift-users > wrote: A narrowing conversion of a floating-point number to an integral type T takes two steps: In the first step, the floating-point number is converted either to a long, if T is long, or to an int, if T is byte, short, char, or int, as follows: If the floating-point number is NaN (§4.2.3), the result of the first step of the conversion is an int or. You can wrap it with an NSDecimalNumber, and then cast it to a Double from there:ĭouble(NSDecimalNumber(decimal:Decimal(1.0))) On Nov 28, 2016, at 2:40 AM, Alex Blewitt via swift-users wrote: (but perhaps we should consider adding initializers that follow the same pattern as Double that don’t have to bridge to solve the problem) (Decimal(1.0) as NSDecimalNumber).doubleValue You can bridge to NSDecimalNumber directly like this: This might be a bit nicer since that is relying on NSNumber bridges.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |