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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:22:16+00:00 2026-06-17T17:22:16+00:00

I have just started out coding in c++ but have quite a bit of

  • 0

I have just started out coding in c++ but have quite a bit of previous experience with MATLAB and MySql. I am trying to calculation some compounding numbers hence accuracy is key. I have tried to do this using double numbers but for some reason I only ever get an accuracy of 7 significant figures (the same as a float). I have even tried using a long double to try the calculations but I still only get 7 s.f. of precision.

Have I not initialised doubles correctly? I thought they were just part of the standard library?? Any help greatly appreciated. The code below gives the main parts of the code in use for the calcuation (the rest is mainly loading data or debug).


UPDATE

Here is a sample of the code (minus data reading). I’ve input the first 5 values. The calculations should give (EXPECTED OUTPUT) Calculated in Excel, using exactly the same input:

0
-1.09526
4.364551963
2.745835774
3.029002506

What the code below gives (ACTUAL OUTPUT):

0
-1.095260000
4.3591394642
2.7340763329
3.0179393198

Code:

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>


using namespace std;

int main(){

std::vector<double> compoundedcalculation; // pre-allocating for the compounded calculations
std::vector<double> dailycompound; // pre-allocating for daily compoundvalue
compoundedcalculation.insert(compoundedcalculation.end(), 0.0); // setting the first value as 0

double dailycompoundval[] = {0,-1.09526,5.46038,-1.61801,0.283089};
dailycompound.assign(dailycompoundval,dailycompoundval+5);
double indCC;

for (int n = 0; n < 5 ;n++)
    {   
    indCC = ((((1+((compoundedcalculation.at(n))/1000))*(1+((dailycompound.at(n))/1000)))-1)*1000);

    printf(" %.17g  \n", indCC);


    compoundedcalculation.insert(compoundedcalculation.end(), indCC ); 
    }
return 0;
}

Thanks for the effort.


UPDATE 2:

Both Expected and Actual Results use the same formula for compounding.

Compounded Total = ((1+(Daily Rate/10000))*(1+(Previous Compounded Total/10000)))

The Daily Rates are:

1st day: 0
2nd day: -1.09526
3rd day: 5.46038
4th day: -1.61801
5th day: 0.283089

  • 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-17T17:22:17+00:00Added an answer on June 17, 2026 at 5:22 pm

    In Visual Studio, double is IEEE754 double precison. That has 53 bits of binary precision, or around 15-16 decimal significant figures.

    Probably your diagnostic code that is printing the values only prints to 7 digits of precision. Or your debugger view only shows 7 digits of precision.

    In other words the problem is not in the underlying data type, but in the way you are viewing that data.

    Update 1

    Your comments indicate that you believe that calculations on double precision values are being carried out to single precision. By default that will not be the case. It could happen if you have change the floating point precision control with a call to _controlfp. However, if your floating point control is set at the default value, then operations on double precision values will not be rounded to single precision.

    Update 2

    Your Excel calculations are performing a different calculation. The output from your C++ program matches the code. The first non-zero value output -1.09526 which matches the code. Because the code says that the value should be dailycompoundval[1]. The corresponding value from your Excel code is -1.095231419 which therefore does not match the C++ code.

    In other words the question is a red-herring. There’s no rounding problems here. The issue is entirely down to discrepancies between the two different versions of your code.

    Update 3

    Your C++ code does not match the expression in the latest update. The code uses a multiplicative factor of 1000, but your expression uses a factor of 10000.

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

Sidebar

Related Questions

I have just started out with testing some php mvc framework In it, it
We have just started out with Team Foundation Server 2008 / Visual Studio Team
I just started out with C and have very little knowledge about performance issues
I just started out using wordpress as a CMS. On the site I have
I have just started learning python version 3 and trying to create a file
I have started coding a packet injector and read up a bit on what
I've just started on some raw network programming in C++ and have been compiling
I have an experience with CakePHP and now started coding on ASP.NET MVC framework.
I have just started studying Android, I have limited java knowledge but am semi
I have just started learning coding and PHP so I have been looking at

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.