truncation...

This is a discussion on truncation... within the C++ Programming forums, part of the General Programming Boards category; well all i want to know is the function that allows you to change lets say 6.984924829 to 6... in ...

  1. #1
    Unregistered
    Guest

    truncation...

    well all i want to know is the function that allows you to change lets say 6.984924829 to 6... in other words i would like to truncate the number ...

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    you dont need a function if you assign that value to an int, it will lose the decimal part.
    Code:
    double dnum = 6.984924829 ;
    int inum;
    
    inum = dnum;   /* inum has a value of 6 */
    or you could use the same variable like
    Code:
    double dnum = 6.984924829 ;
    
    dnum = (int)dnum;   /* dnum now has a value of 6.0 */
    All spelling mistakes, syntatical errors and stupid comments are intentional.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer truncation
    By Magos in forum C++ Programming
    Replies: 6
    Last Post: 02-27-2006, 03:26 PM
  2. No truncation?
    By SirCrono6 in forum C++ Programming
    Replies: 6
    Last Post: 02-19-2006, 01:18 AM
  3. Converting a float to an int without truncation
    By SETmajor in forum C++ Programming
    Replies: 3
    Last Post: 06-16-2004, 01:39 AM
  4. Try out my new game :) !
    By Stan100 in forum Game Programming
    Replies: 10
    Last Post: 06-05-2003, 09:10 AM
  5. Warning message truncation 'double' to 'float'
    By Tojam in forum C Programming
    Replies: 4
    Last Post: 05-01-2002, 03:21 AM

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