Question regarding extraction of value from a decimal fraction

This is a discussion on Question regarding extraction of value from a decimal fraction within the C Programming forums, part of the General Programming Boards category; Dear All, I want to extract the integer value just after the decimal point from any number, for example integer ...

  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
    21,397
    #include <math.h> and use fmod.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21