[swift-evolution] Is there a need for a Decimal type?

Dale Buckley dalebuckley86 at gmail.com
Sat Feb 13 05:51:39 CST 2016


We all know the problems with floating point types, they are well documented and well understood by developers everywhere. We know when to use them and (hopefully) when not to use them and if you are working with financial values on a Foundation based platform you know to not use a floating point type and to use NSDecimalNumber instead.

My question is this; should there be an equivalent NSDecimalNumber type built into Swift that can be used for precision sensitive decimal values where floating point types can’t be used?

Maybe the answer isn’t an ‘equivalent’ as such, it would probably have a modern twist so I can see it looking like something else entirely, but the point still stands.

I feel like there is a need for this, it’s not a new problem and has been solved many times over in other languages such as Objective-C (NSDecimalNumber) and Java (BigDecimal) etc. Yet as it stands we seem to be lacking an equivalent solution in Swift. It shouldn’t be left for an external library to solve, it’s one of those things that need to be built into the language.

What are peoples thoughts on this?


More information about the swift-evolution mailing list