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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:57:48+00:00 2026-06-07T08:57:48+00:00

I want to know if there is a simple function that I can use

  • 0

I want to know if there is a simple function that I can use such this sample.
I have a

float value = 1.12345;

I want to round it with calling something like

float value2 = [roundFloat value:value decimal:3];
NSLog(@"value2 = %f", value2);

And I get “1.123”
Is there any Library or default function for that or I should write a code block for this type of calculations?

thank for your help in advance

  • 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-07T08:57:49+00:00Added an answer on June 7, 2026 at 8:57 am

    Using NSLog(@"%f", theFloat) always outputs six decimals, for example:

    float theFloat = 1;
    NSLog(@"%f",theFloat);
    

    Output:

    1.000000
    

    In other words, you will never get 1.123 by using NSLog(@"%f", theFloat).

    Cut-off after three decimals:

    float theFloat = 1.23456;
    float newFLoat = (int)(theFloat * 1000.0) / 1000.0;
    NSLog(@"%f",newFLoat);
    

    Output:

    1.234000
    

    Round to three decimals (using roundf() / lroundf() / ceil() / floor()):

    float theFloat = 1.23456;
    float newFLoat = (int)(roundf(theFloat * 1000.0)) / 1000.0;
    NSLog(@"%f",newFLoat);
    

    Output:

    1.235000
    

    Round to three decimals (dirty way):

    float theFloat = 1.23456;
    NSString *theString = [NSString stringWithFormat:@"%.3f", theFloat];
    float newFloat = [theString floatValue];
    NSLog(@"%@",theString);
    NSLog(@"%f",newFloat);
    

    Output:

    1.235
    1.235000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know is there any way that I can remove duplicates from
I know there is this post , but I still want to know more
I want to know if there is any way by which I can paste
Are there any pre-made scripts that I can use for PHP / MySQL to
I know that I can use FOR EACH to easily accomplish my goal below,
I have wrote a simple client that use TcpClient in dotnet to communicate. In
I'm looking for a hash function that I can use to give uniform unique
Possible Duplicate: Can anyone recommend a simple Java web-app framework? I want to know
i want to know there a limitation in size for an iphone to display
I'm making a chat responder for a game and i want know if there

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.