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 7413729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:57:00+00:00 2026-05-29T06:57:00+00:00

I have an input with UIKeyboardTypeDecimalPad and I need my user to input a

  • 0

I have an input with UIKeyboardTypeDecimalPad and I need my user to input a float (with unlimited characters after a dot). After the input I filter the string with :

NSString *newValue = [NSString stringWithFormat:@"%.f",[textField.text floatValue]]

But that gives me a lot of unnecessary digits after a dot (for example for 2.25 it gives 2.249999).

All I need is to filter the input so it’ll be a legal float (digits and not more than one dot).

How do I do that?

  • 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-05-29T06:57:01+00:00Added an answer on May 29, 2026 at 6:57 am
    NSString *newValue = [NSString stringWithFormat:@"%0.1f", [textField.text floatValue]];
    

    the number after the dot is the number of decimal places you want.

    UPDATE:
    You could use string manipulation to determine the number of decimal places the user typed in (don’t forget to check for edge cases):

    NSInteger numberOfDecimalPlaces = textString.length - [textString rangeOfString:@"."].location - 1;
    

    and then if you want to create a new string with a new float to the same level of display precision you could use:

    NSString *stringFormat = [NSString stringWithFormat:@"%%0.%if", numberOfDecimalPlaces];
    NSString *newString = [NSString stringWithFormat:stringFormat, newFloat];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have input[type=text] where user can type only alpha, space and comma. I need
How to rewrite Webconfig connection string at runtime.I have input textbox for Server,UserName and
I have input string DISPLAY_MSG='Kumar + sajdhjhasd - Type' and ID=156090 and RESOURCE_KEY='Ascend.ElementMaster.kumar_type.desc' and
I have input string as below (abc xyz OR def) AND (ghi OR jkl)
I have input tags with a user defined attribute as:- <input name=grp1 type=radio myUDF=value1
I have input that may either be a string or be a string of
I have input.txt 1 2 3 4 5 I need to get such output.txt
I have a method that have input variable and I need to schedule this
Hi I have a simple form that allows a user to input a name,
If I have input string in C#, how can I do series of Regex

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.