0

Hi All,

I'm having a weird problem. I'm trying to do division like this:

vector = timeStamp / 12800.0;

where vector is a double and timeStamp is an int. The answer that I get is a double, however it's only to 2 places of precision. For instance 28521602 / 12800 = 2228.25015625 but it's chopping it off to 2228.25. I'm using GCC to run and compile my code, any help would be greatly appreciated. Thanks,

Bleh

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by VernonDozier
0

Hi All,

I'm having a weird problem. I'm trying to do division like this:

vector = timeStamp / 12800.0;

where vector is a double and timeStamp is an int. The answer that I get is a double, however it's only to 2 places of precision. For instance 28521602 / 12800 = 2228.25015625 but it's chopping it off to 2228.25. I'm using GCC to run and compile my code, any help would be greatly appreciated. Thanks,

Bleh

vector is not getting chopped off in memory, just in the display. It is stored in memory correctly. What IS being chopped off is the DISPLAY to the screen of vector. cout has a default of 6 significant digits with doubles, which can be changed with setprecision.

#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
    int timestamp = 28521602;
    double vector = timestamp / 12800.0;
    cout << setprecision(20) << vector << endl;
 
    return 0;
}

http://bytes.com/forum/thread531727.html

0

Thanks! Also was wondering if there is an easy to convert a string to a double...

-BLEH

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.