[swift-evolution] Still Missing: Fixed Decimal Numerical Type.

Ted F.A. van Gaalen tedvgiosdev at gmail.com
Wed Mar 30 08:09:58 CDT 2016

There is still no fixed decimal numerical type available in Swift!

It should be  implemented *as soon as possible* 
because the fixed decimal type is really needed 
for applications working with financial and statistical data!

var depositPromille: Decimal(10,3) = -1234.56
typealias  Money = Decimal(20,2) 

Important: Implementation should be on a low level
and must be very, very efficient!
This is because usually in financial applications 
very large amounts of data (e.g. bank accounts) are processed. 

I’d suggest that Swift could deploy already existing
Fixed Decimal library functions available. 
In fact, many do exist, for example here:

Of course, the fixed decimal type is also available in most relational databases,
currently there is no 1:1 way to get this type of data   DB <—> Swift,
and to process it easily in Swift. One now has to convert it e.g.
to large integers, thereby also somehow remembering the decimal fraction.
Yes, one could write a class/struct for it, but one also has
to implement all the arithmetic involved, with also needs 
rounding, truncation, etc. It would also be too slow.

For those still considering using floating point types
for this purpose e.g. Double: Forget it, because 
floating point types don’t have the required exact precision.
E.g. € 234,565,098.01   // the one cent at the end is important!

For some idea  on how this could be implemented in the Swift language
please read a PL/1 manual, like this one: 

http://www.ibm.com/support/knowledgecenter/#!/SSY2V3_4.3.0/com.ibm.entpli.doc_4.3/lr/preface_plugin.htm <http://www.ibm.com/support/knowledgecenter/#!/SSY2V3_4.3.0/com.ibm.entpli.doc_4.3/lr/preface_plugin.htm>

especially under sub-topic “Data elements” 

Kind Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160330/d2e41428/attachment.html>

More information about the swift-evolution mailing list