[swift-evolution] [Pitch] Percentage Type
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.
> 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).
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution