[swift-evolution] [Pitch] Percentage Type

Jon Gilbert swiftevolution at jongilbert.com
Tue Jan 16 10:56:02 CST 2018


No to this pitch, because a percentage can be higher than 100%.

Use NumberFormatter to display a number as a percentage. https://developer.apple.com/documentation/foundation/numberformatter

Or you could make an NSNumber subclass if you want to enforce an arbitrary rule upon numbers.

Jonathan

> On Jan 13, 2018, at 18:26, Jonathan Hull via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hi Evolution,
> 
> I was wondering if we would consider adding a percentage type to Swift.  This would be a type with a value between 0 & 1.
> 
> I know we can and do use doubles or floats for this now, but there really is a semantic difference between most parameters that take a value between 0 & 1 and those that take any floating point value.  It would be nice to have a type that semantically means that the value is from 0 to 1.
> 
> It could even just wrap a Double for speed (in my own code I wrap a UInt64 for decimal accuracy… and to avoid issues around comparisons).
> 
> Thanks,
> Jon
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20180116/0619b453/attachment.html>


More information about the swift-evolution mailing list