O'Reilly logo

Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming by Erica Sadun, Rod Strougo, Maurice Sharp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Formatting and Reading Numbers

So far you have only localized strings in the CarValet app. Numbers and dates also vary in formatting from locale to locale. In iOS, the language and locale are set separately, as you saw in Figure 5-1. One simple example is a device using English for the language and Canada for formats.

As mentioned previously, German numbers reverse the period and comma separators. The number 1,234.56 in English is 1.234,56 in German. At the moment, you are showing the fuel amount using stringWithFormat: and reading it with floatValue. Neither of these methods works with localized numbers. For that, you need NSNumberFormatter, a class for both creating and parsing localized numbers as well as other formatting tasks. Creating a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required