Hello DP Forum People, I have this problem of getting the decimal of a number? How can I get it and copy to a variable? ex.... 1234.59 I used a for loop in order to get the index value of 59, my problem was with the value? how can I transfer this index number to a variable?
Use modf. (This is to someone who's looking for the same thing) //Example will output decimal and integer parts of 12.34 #include <cmath> #include <iostream> using namespace std; int main() { double x; modf(12.34, &x); cout<<"Decimal: "<<modf(12.34, &x)<<"Fractional: "<<x; } Code (markup):