C language index value to variable?

Discussion in 'Programming' started by reinvaldez, Jan 28, 2009.

  1. #1
    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?
     
    reinvaldez, Jan 28, 2009 IP
  2. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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):
     
    NeoCambell, Dec 18, 2009 IP