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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:24:25+00:00 2026-05-25T11:24:25+00:00

Say I have a method returning a double , but I want to determine

  • 0

Say I have a method returning a double, but I want to determine the precision after the dot of the value to be returned. I don’t know the value of the double varaible.

Example:

double i = 3.365737;
return i;

I want the return value to be with precision of 3 number after the dot

Meaning: the return value is 3.365.

Another example:

double i = 4644.322345;
return i;

I want the return value to be: 4644.322

  • 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-25T11:24:25+00:00Added an answer on May 25, 2026 at 11:24 am

    What you want is truncation of decimal digits after a certain digit. You can easily do that with the floor function from <math.h> (or std::floor from <cmath> if you’re using C++):

    double TruncateNumber(double In, unsigned int Digits)
    {
        double f=pow(10, Digits);
        return ((int)(In*f))/f;
    }
    

    Still, I think that in some cases you may get some strange results (the last digit being one over/off) due to how floating point internally works.


    On the other hand, most of time you just pass around the double as is and truncate it only when outputting it on a stream, which is done automatically with the right stream flags.

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

Sidebar

Related Questions

Let's say I have a WCF service which has a method returning object Person.
Say I have the following class with a method returning a list: class C:
Say I have a method that I wish to call which has an argument
Say I have a method, and within that method it instantiates a Person class:
Let's say I have a method in java, which looks up a user in
Let's say I have a method: bool myMethod(int a) { //return a bool }
I'm using .NET 3.5. Say I have a method that accesses a specific file,
Say I have this simple method: public IEnumerable<uint> GetNumbers() { uint n = 0;
Let's say I have a subroutine/method that a user can call to test some
Let's say that I have a method that looks like this: def raise_if_client_status_error(xml_resp) #

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.