large double values from text file

Hey everyone.. I am having an issue with this program that I am working on.. Not sure if I am using something wrong and should try something different.. but generally I am inputting large double values from a text file.. These values are like: 178909.95 but when I use A[ix] = stod(line).. to convert the string line into a double I only get 178910 and it cuts off the decimal values. I am wondering if it is the stod that is causing it? I have tried using stold and it results in the same issue... Anyway thanks in advance

Here is what my code looks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  double* loadArray(string fileName, int size) {
	string line;
	ifstream file;
	double* A = new double[size];
	int ix = 0;

	file.open(fileName);
	if (file.is_open()) {
		while (getline(file, line)) {
			A[ix] = stod(line);
			ix++;
		}
		file.close();
	}
	return A;
   }


and here is a picture of the input text file and what it output http://i.imgur.com/8mYWoGN.png
These values are like: 178909.95 but when I use A[ix] = stod(line).. to convert the string line into a double I only get 178910 and it cuts off the decimal values.

What makes you think it's cutting off the value?

What would you expect the following program's output to be?

1
2
3
4
5
6
7
// http://ideone.com/MHV642
#include <iostream>
     
int main()
{
    std::cout << 178909.95 << '\n';
}


Does it meet your expectations?

How 'bout with a little change...

1
2
3
4
5
6
7
8
9
// http://ideone.com/oH6sYu
#include <iostream>
#include <limits>

int main()
{
    std::cout.precision(std::numeric_limits<double>::digits10);
    std::cout << 178909.95 << '\n';
}
You are awesome thank you so much!
Topic archived. No new replies allowed.