Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Double to integer conversion whithout loss of numbers - c++

$
0
0
hello,

c++


cout << 9.45 * 100 << endl;

double a;
	double b;
	int c;



	b = 9.45;

	a = b*100.0;
c=a;
	cout << c <<endl<<endl  ;
	cout << a << endl;



Results

945
944 <<<<<----------- THIS ONE I MEAN, some numbers are ok but 9.45 comes out 944 instead of 945 is there any way to stop this

945


thanks a million!!!

when i insert 2.15
int main()
{

	cout << 2.15 * 100 << endl;

double a;
	double b;
	int c;



	b = 2.15;

	a = b*100.0;
c=a;
	cout << c <<endl<<endl  ;
	cout << a << endl;

	return 0;
}



result

215
215

215

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>