Thread: Question regarding extraction of value from a decimal fraction

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    69

    Question regarding extraction of value from a decimal fraction

    Dear All,


    I want to extract the integer value just after the decimal point from any number, for example integer 1 from 1.250. Below is my code for the same. However, I get an error while extracting the integer value(written below the code):

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    int main()
    {
        float i=1.25,num=0;
        num=i%10;
        printf("%f",num);
        system("pause");
        return 0;
    }
    "invalid operands to binary % "

    Please suggest modifications/changes. Thank you.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    #include <math.h> and use fmod.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    69
    Solves my problem, thanks .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 18
    Last Post: 03-26-2008, 09:01 AM
  2. Decimal question
    By aff501 in forum C Programming
    Replies: 4
    Last Post: 07-12-2006, 06:01 PM
  3. Question about decimal places
    By RealityFusion in forum C++ Programming
    Replies: 2
    Last Post: 05-21-2006, 11:47 AM
  4. Fraction outputted as decimal
    By blindman858 in forum C++ Programming
    Replies: 3
    Last Post: 06-04-2005, 01:17 PM
  5. Quick decimal question
    By ColdFire in forum Windows Programming
    Replies: 3
    Last Post: 09-30-2002, 07:16 PM

Tags for this Thread