Thread: Need help in getting the integer value

  1. #1
    Registered User
    Join Date
    Sep 2005

    Need help in getting the integer value

    Hello I wrote this small. It takes a number fron 1 - 1024 rescales it and gives out a number between 1 - 363. But P_Number is a float. Is it possible to calculate P_Number as a float but only accept the integer part of the result. (e.g. if P_Number = 127.946) is it possible only to accept 127 or 128 and ignore the 0.946 part and send the integer result only to calculate DC. I don't really care if DC is a floating point number but I need the P_number to be an interger. If so can someone please show me how. I appreciate any help from anyone.

    #include <stdio.h>
    int main()
        float P_Number, DC, A_Number;
        printf("please enter the conversion number: ");
       P_Number = (A_Number/1024)*363;
       printf("The P_number is %f \n", P_Number);
       DC = P_Number / 3.63;
       printf("The DC is %f \n", DC);
     return 0;

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    I believe if you declared P_Number as an int and did
    P_Number = (A_Number*363)/1024;
    you would get what you want (since 1024*363 shouldn't overflow anything -- edit unless you have 2-byte ints). Integer division will always round down, which seems like what you want.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM