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

  • Home
  • SEARCH
  • 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 9215285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:10:14+00:00 2026-06-18T02:10:14+00:00

With the following 2 functions focus on the rows with the * comments. When

  • 0

With the following 2 functions focus on the rows with the * comments. When the cout<< statement executes, there is no decimal place showing. 3021680380 /10000000 turns into 302. instead of 302.1680.

void convert(){
    setprecision(4);   //************************
    newFileTime = new double[numRec];   //***********
    newOffset = new int[numRec];
    newSize = new int[numRec];
    newNum = new int[numRec];
    newType = new int[numRec];
    newTime = new int[numRec];

    for(int i = 0; i<numRec; i++){
        newFileTime[i] = fileTime[i] / 10000000; //**********
        newOffset[i] = offset[i] / 512;
        newSize[i] = fileSize[i] / 512;
        newNum[i] = 0;
        if(type[i] == "Write"){
            newType[i] = 0;
        }else{
            newType[i] = 1;
        }
        newTime[i] = responseTime[i] / 10000000;
    }
}

void exports(){
    setprecision(4);  //**************
    ofstream fout;
    fout.open("prxy_0.ascii");
    {
    if(!fout){
            cout <<"File opening failed. \n";
        }
    }
    fout<< numRec <<endl;

    for(int i = 0; i < numRec; i++){
        fout<< newFileTime[i] << " " << newNum[i] << " " << newOffset[i] << " " << newSize[i] << " " << newType[i] << " " << newTime[i];
        cout<< fileTime[i] << " " << newFileTime[i] <<endl; //**********
        if(i != numRec - 1){
            fout<<endl;
        }
    }
    fout.close();
}

Any ideas?

  • 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-18T02:10:15+00:00Added an answer on June 18, 2026 at 2:10 am

    Whenever you divide two integers, the result of this expression also is an integer. Integer division is always rounded down.

        newFileTime[i] = fileTime[i] / 10000000;
        //               ^^^^^^^^^^^   ^^^^^^^^
        //                   int          int
    

    To fix your expression, cast one of the operands to a double to make the division a floating point division (use one of the following possibilities):

        newFileTime[i] = static_cast<double>(fileTime[i]) / 10000000;
        // or
        newFileTime[i] = fileTime[i] / 10000000.0;
    

    Please note that setting the precission requires you to put the call of std::setprecision(...) into the stream for which you want to set the precision. Also, this only sets the output precision (when writing to the stream), not how the calculations are performed:

        std::cout << std::setprecision(4) << [some double values]
    

    Also note that std::setprecision sets the number of magnificant digets rather than the decimals after the decimal point. So your 302.1680 would be printed as 302.2 (four maginificant digits). To set a fixed number of digits after the decimal point, also write std::fixed to the stream, either before or after std::setprecision:

        std::cout << std::fixed << std::setprecision(4) << [some double values]
    

    Note that such configurations will be kept during the runtime of your program until you change them again. To keep them local in a function, make sure that you restore the configuration after you’re done.

    Of course, std::cout was only an exemplary stream. The same applies for writing to files (any std::ostream object).

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

Sidebar

Related Questions

I have the following function in JavaScript every part of the if statement executes
In my MVC application in Controller i have following function to add and focus
I'm using the following functions: # The epoch used in the datetime API. EPOCH
I am using the following functions for writing and reading 4098 floating point numbers
I'm using PostgreSQL 9.1.3 and the following functions: CREATE OR REPLACE FUNCTION cad(INOUT args
On my front end, I have following functions: method to encrypt: public static string
The following two functions are extremely similar. They read from a [String] n elements,
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )
For example suppose I have the following two functions function a(param1) { console.log(param1); }
I have a few issues with the following php functions (part of a bigger

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.