Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:19:34+00:00 2026-06-07T15:19:34+00:00

I am using the keyboard type: UIKeyboardTypeDecimalPad for two UITextField objects. When trying to

  • 0

I am using the keyboard type: UIKeyboardTypeDecimalPad for two UITextField objects.
When trying to perform an addition, I get different results depending on the current locale:

Case 1: US Format: the decimal point appears as . as expected. If I add 12.3 (text field 1) + 12.3 (text field 2), the answer will be 24.6. That’s what I want. But:

Case 2: Egypt Format: the decimal point appears as ,. If I repeat the same calculation the answer will be 24. The decimal portion is ignored. Is there a fix for that?

Note: I used the [textField.text floatValue] method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:19:36+00:00Added an answer on June 7, 2026 at 3:19 pm

    Because floatValue does non-localized scanning, it expects a “US format”.

    You can use an NSScanner object for localized scanning of numeric values from a string.

    See: String Programming Guide: Scanners

    Note the last paragraph:

    Localization

    A scanner bases some of its scanning behavior on a locale, which
    specifies a language and conventions for value representations.
    NSScanner uses only the locale’s definition for the decimal separator
    (given by the key named NSDecimalSeparator). You can create a scanner
    with the user’s locale by using localizedScannerWithString:, or set
    the locale explicitly using setLocale:. If you use a method that
    doesn’t specify a locale, the scanner assumes the default locale
    values.

    See also: How to do string conversions in Objective-C?

    Example:

    NSScanner *scanner = [NSScanner localizedScannerWithString:textField.text];
    double mynumber;
    if([scanner scanDouble: &mynumber]){
      // do something
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Extremely basic question. Are there common actions I can perform using keyboard shortcuts in
I'm trying to hook up a keyboard shortcut for my chrome extension. I'm using
I have an EditText using android:inputType=textPostalAddress as the keyboard type. I would like it
I have a UITextField for a username, and I set the keyboard type to:
I can not type in Emulator using PC-Keyboard. can anyone help me ?
Using spreadsheetgear, is there any way to get the probable data type for a
I'm trying to type some text into a text field using the Robot class
How to navigate the image using Keyboard arrow keys in C#. My 1st form
I know how to replace text in a string. But that's using keyboard (ASCII)
I'm using Resharper keyboard shortcuts all the time and it helps a lot in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.