•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,074 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,329 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 218 | Replies: 3
![]() |
•
•
Join Date: Jun 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hi All,
I'm having a weird problem. I'm trying to do division like this:
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
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
•
•
Join Date: Jan 2008
Posts: 1,747
Reputation:
Rep Power: 8
Solved Threads: 217
•
•
•
•
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
Last edited by VernonDozier : Jul 24th, 2008 at 12:02 pm.
•
•
Join Date: Jan 2008
Posts: 1,747
Reputation:
Rep Power: 8
Solved Threads: 217
•
•
•
•
Thanks! Also was wondering if there is an easy to convert a string to a double...
-BLEH
Use strtod from cstdlib. You'll need to convert the string to a c-string before applying strtod.
string stringNum = "67.34512"; double number = strtod(stringNum.c_str(), NULL);
http://www.cplusplus.com/reference/c...ib/strtod.html
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C++ Forum
- Previous Thread: *.stl files
- Next Thread: binay heap and binary search tree help



Linear Mode