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@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@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to