Clarification: Type cast double to int

This is a discussion on Clarification: Type cast double to int within the C Programming forums, part of the General Programming Boards category; Hi Guys, I'm using Code: static_cast<int> on a double. Can someone please correct me if I'm wrong etc... But does ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    224

    Cool Clarification: Type cast double to int

    Hi Guys,

    I'm using
    Code:
    static_cast<int>
    on a double.

    Can someone please correct me if I'm wrong etc...

    But does this just remove everything after the decimal point??

    e.g. If my double was 1.99999
    Then after this operation it would give me an integer of 1?

    Cheers,

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    That's C++, not C. The result will be rounded down, but it does not change the value of the variable itself.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. type cast problem
    By tikelele in forum C Programming
    Replies: 10
    Last Post: 10-31-2007, 10:23 PM
  2. Replies: 4
    Last Post: 12-02-2004, 01:57 PM
  3. Replies: 2
    Last Post: 09-10-2002, 10:03 PM
  4. type cast to a pointer....
    By rc7j in forum C++ Programming
    Replies: 2
    Last Post: 02-05-2002, 04:13 PM
  5. type cast or conversion?
    By steviecrawf in forum C Programming
    Replies: 2
    Last Post: 11-21-2001, 03:08 PM

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