How to extract the int part and the decimal part from double number in C++

1 Answer

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

using namespace std;

int main() 
{ 
    double f = 376.287152; 
    double fractionpart, intpart;
 
    fractionpart = modf(f, &intpart);
 
    cout << intpart << endl;
    cout << fractionpart << endl;

    return 0; 
}   
       
 
       
/*
run:
       
376
0.287152
     
*/

 



answered Aug 26, 2019 by avibootz

Related questions

...