Safe way to go from a float or double to an int

This is a discussion on Safe way to go from a float or double to an int within the C Programming forums, part of the General Programming Boards category; Is there a way to convert a float or double to an int without triggering a warning? I'm kinda anal ...

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    Safe way to go from a float or double to an int

    Is there a way to convert a float or double to an int without triggering a warning?

    I'm kinda anal and hate having warnings show up when I compile.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You can just cast it.

    Code:
    float f = 10.f;
    int x;
    
    x = (int)f;
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Ah thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NEED HELP READING FILE and PRINTING
    By geoffr0 in forum C Programming
    Replies: 4
    Last Post: 04-16-2009, 06:26 PM
  2. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  3. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 07:45 AM
  4. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 07:34 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM

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