0

Now functions strtod and strtol support parsing hex number format, infinity, NaN and other non-standard formats.

But how to convert string to number using only classic format: 123, 1.23, 0.123, -123, 1.23e10, 1.23e-10 ?

Not: +123, .123, 0xabcd, 0123 and etc?

iOS User
  • 101
  • 1
  • 8
  • Which programming language is this? – Uwe Keim Mar 26 '17 at 07:43
  • I am using `Swift` or `ObjC` – iOS User Mar 26 '17 at 07:46
  • Probably you will get _way_ better answers if you tag your question accordingly. – Uwe Keim Mar 26 '17 at 07:50
  • We require exactly "classic format". Non-standard notation is wrong in our case. – iOS User Mar 26 '17 at 08:06
  • What exactly *is* the "classic format"? – Martin R Mar 26 '17 at 08:14
  • I have already mentioned: `123`, `-123`, `1.23`, `-1.23`, `1e23`, `-1e23`, `1.2e3`, `-1.2e3`, `1E23`, `-1E23`, `1.2E3`, `-1.2E3`. – iOS User Mar 26 '17 at 08:18
  • In your "classic format", what about international users? In Germany, they use `,` for decimal point, e.g. `-1,23`. – Rob Mar 26 '17 at 09:11
  • 1
    Bottom line, what we're all dancing around is that we don't use `strtod` functions nowadays. If parsing some system generated string (e.g. something you might find in JSON, you'd just do `Int("123")` or `Double("1.23")`. Or if this was a number provided by a user, you'd use `NumberFormatter` to handle input more flexibly, i.e., consistent with the device's locale. – Rob Mar 26 '17 at 09:19

0 Answers0