How to get the integer and the fraction part of double number in C++

1 Answer

0 votes
#include <iostream>
#include <cmath>

using std::cout;
using std::endl;

int main()
{
	double d = 3.14, integer, fraction;
	
	fraction = modf(d, &integer);

	cout << "Integer = " << integer << " Fraction  = " << fraction << endl;

	return 0;
}


/*
run:

Integer = 3 Fraction  = 0.14

*/

 



answered May 12, 2018 by avibootz
...