Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-02-2009, 12:02 AM   PM User | #1
Advancedkill
New Coder

 
Join Date: May 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Advancedkill is an unknown quantity at this point
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
Advancedkill is offline   Reply With Quote
Old 08-02-2009, 12:10 AM   PM User | #2
BrickInTheWall
Regular Coder

 
BrickInTheWall's Avatar
 
Join Date: Mar 2009
Location: Munich, Germany
Posts: 139
Thanks: 1
Thanked 13 Times in 13 Posts
BrickInTheWall is on a distinguished road
yes that works. Look up type casting for C/C++ to see what can be cast implicitly and what requires explicit conversions.
BrickInTheWall is offline   Reply With Quote
Old 08-02-2009, 12:11 AM   PM User | #3
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
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
oracleguy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:44 PM.


Advertisement
Log in to turn off these ads.