Print double value without the decimal, but still keep numbers

closed account (1374LyTq)
Hi everyone!
I am summing double values but I want to file_out the sumpayments without the decimal but still keep the reminding value of the decimal so for example:
23.07 becomes 2307
17.96 becomes 1796

In this case sumRN is 1888.11 but I want it displayed as 188811

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using namespace std;
int main()
{       string customersName;
	string customerID;
	string header;
	string accountNumber;
	ifstream file_in;
	ofstream file_out;
	int i = 0;
	long long int  RoutingNumber;
	double rate;
	double sumpayments;
	sumpayments = 0;

	file_in.open("data_record.txt");
	file_out.open("emt_out.txt");

	getline(file_in, header);

	while (!file_in.eof())
	{
		i++;
		getline(file_in, customersName, ',');
	        file_in >> RoutingNumber;
		file_in.ignore();
		getline(file_in, accountNumber, ',');
		file_in.ignore();
		file_in >> rate;
		file_in.ignore();
		file_in >> customerID;
		file_in.ignore();

		sumpayments += rate;

		cout << "this is rates " << rate << endl; //used to make sure 
                  that the  rates are correct
	}
	cout << "test " << sumRN << endl;


	system("pause");
	return 0;

}
Last edited on
I love how your code snip is incredible useless.
¿what part should I look at?
`sumRN' appears only one single time, and with "test" before, so going to ignore it.
the other output is just "to make sure", so ignoring that too.

> 23.07 becomes 2307
mutiply by 100 and take the integer.


> while (!file_in.eof())
I hope that you end up reading the last line twice.
if they are all 2 digits X 100 works. If they are not, convert the double to a string, cap the period, and convert back is a crude but simple and effective way to do it. if they are not all the same order, comparison or addition etc won't give meaningful results.
Last edited on
closed account (1374LyTq)
ne555, I love that you love that too!! Sorry, but this is the beginners forum and my first post so how about pointing the error out without the sarcastic undertone.

I am aware that it will read the last line twice but my professor wants us to learn this command.

Thanks for the answers. It was as simple as multiplying it by a 100, haha :)
Topic archived. No new replies allowed.