Doubles

Jan 30, 2011 at 2:55pm
Is there any way to prevent doubles from rounding? I'm preforming operations like multiplying and dividing but it rounds the double. Is there a way to prevent this or is it DevC++ being dumb?
Jan 30, 2011 at 3:07pm
What do you mean? If you output the result of an integer, the result would obviously get casted. Without you telling us what exactly you do, it's hard to tell what your problem is. Oh and:
http://www.jasonbadams.net/20081218/why-you-shouldnt-use-dev-c/
Jan 31, 2011 at 12:24am
Alright so I have a program that is doing calculations based on what the user types in. So it the user types 23.42 and then * and then 1234.412, it would give them 28909.9 when my calculator gives me 28909.92904. Why is that?
Last edited on Jan 31, 2011 at 12:25am
Jan 31, 2011 at 12:30am
1
2
3
4
5
6
7
8
9
10
#include <iomanip>
#include <iostream>

int main()
{
  double d = 23.42 * 1234.412;
  // the rounding is from cout. double's are always precise, cout rounds. You need these from the iomanip header.
  std::cout << std::fixed << std::setprecision(5) << std::showpoint << d << std::endl;
  return 0;
}
Jan 31, 2011 at 12:36am
Just making sure, if I use: using namespace std; I don't have to type the "std::" right?
Jan 31, 2011 at 12:38am
That is correct.
Jan 31, 2011 at 12:38am
Alright thanks!
Topic archived. No new replies allowed.