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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:02:58+00:00 2026-05-23T16:02:58+00:00

I have an API call which returns a double. The double’s decimal length can

  • 0

I have an API call which returns a double. The double’s decimal length can variate from many decimal places to a few (it all comes down to the state of an actuator). This double represents the current position on the range radius of an actuator.
I am not interested in such a detailed number, because it adds alot of noise to the system.
I’ve been using floats to save space, but still I have floats which have 6-8 decimal length.
I am not interested in floor or ceil, simply because it doesn’t do the job i want.
For example, I have the numbers:

-2.05176
-0.104545
 0.30643
 0.140237
 1.41205
-0.176715
 0.559462
 0.364928

I want the precision to be set to 2 decimal places no matter what.
I am NOT talking about the output precision on std::cout, I know how to set this. I am talking about the actual precision of the float. i.e: I am interested in floats who will have 0.XX format and 0.XX00000000000 actual precision.
Therefore transforming the above list to:

-2.05
-0.10
 0.30
 0.14
 1.41
-0.17
 0.55
 0.36

I know boost has a numerical conversion template, but I cannot figure out how to convert from float to float using a lower precision. Can somebody please help ?

  • 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-23T16:02:59+00:00Added an answer on May 23, 2026 at 4:02 pm

    Can’t you just round it.

    float round(float num, int precision)
    {
        return floorf(num * pow(10.0f,precision) + .5f)/pow(10.0f,precision);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to call an external API which returns XML, and i have no
I have this function: RegisterGlobalHotKey(Keys.F6, MOD_SHIFT | MOD_CONTROL); which call an API to register
I'm currently calling the Facebook graph API from one of my actions which returns
I have an API call in my application where I am checking the time
I have an API that can be implemented by various vendors. I can send
I have a scenario in which I have REST API which manages a Resource
So Google Analytics does not have an API that we can use to get
I have method which return the latitude of the location public double[] getlat(){ double
I have a REST-ish API that returns JSON. One of the output fields is
I am using the queue api and have encountered to errors which crash my

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.