You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm reluctant to add this to the default (non-locale-aware) initializer.
Two concerns:
I want to leave the default initializer here very plain with no options so we can drive performance for things like JSON parsing.
As Richard says, this is true "in English" but other languages handle things differently.
I would prefer a separate initializer such as `Double("10,204", locale: ....)` or `Double("10,204", options: ...)` that can handle this in varying ways depending on needs. There are likely other designs, of course; I don't think we yet have an established pattern for how to handle locale-sensitive issues in the standard library.
Actually, I agree with Tim Kientzie. I've been considering an extension of Double that does this. Should be quite simple to do. Actually, let me restate my original post:
There should be a standard way to convert user-entered numeric strings (of all relevant types) to handle common user input strings, such as numbers which contain group separators. And this should be done in a locale-aware way.
I'm fine with XXX(_:String, locale: Locale) where XXX is Int, Double, Float, etc. I just think that since converting user input is a common use of these initializers, that it would be a good addition to Standard Library to include them.
Locale-dependent formatting is something that we've fairly intentionally wanted to keep out of the standard library (and leave to higher-level libraries).
Additional Detail from JIRA
md5: 8ba1ca8a87224f28b60a97f254045948
Issue Description:
In English, a number like "10,204" (including the comma [acting as a grouping character]) is a valid string. However,
Double("10,204") produces nil, while Double("10204") does not.
The Standard Library should be updated such that both inputs produce the same (correct) output.
The text was updated successfully, but these errors were encountered: