Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Convert decimal values to integers

    Hi

    If I want to assign the value 3 to an integer variable by doing 10/3 (and forgetting about the remainder) how would I do this? (Using C for my language)

    Would

    Code:
    int x = 10/3;
    always work?

    Thanks

  • #2
    Regular Coder BrickInTheWall's Avatar
    Join Date
    Mar 2009
    Location
    Munich, Germany
    Posts
    139
    Thanks
    1
    Thanked 13 Times in 13 Posts
    yes that works. Look up type casting for C/C++ to see what can be cast implicitly and what requires explicit conversions.

  • #3
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Yes, but if you want to be sure you could floor function. (I'm assuming that you aren't going to be assigning a constant that way, that the input is actually going to be dynamic.)
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •