View Single Post
  #2   Spotlight this post!  
Unread 28-01-2005, 22:40
colt527 colt527 is offline
Registered User
AKA: Ken Colton
FRC #0527
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Long Island
Posts: 123
colt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to behold
Send a message via AIM to colt527
Re: Converting floating point to integers

This SHOULD make no difference, but sometimes code is like that. Dont declare a new variable for it. Just do:

float f = 245.56;
printf("%d\n", (int)f);

I've never had a problem doing it that way *shrugs* ... hope it works.

EDIT: actually, i think if you wanted to do it you way, just cast it again inside the printf, like this:

float f = 245.56;
int i;
i = (int)f;
printf("%d\n", (int)i);

I vaguely remember something about printf that if you dont cast inside the function, it does some weird things. Hope one of those works!
__________________
Mentor, Team 527 -- Plainedge Red Dragons
FIRST Volunteer
SUNY Stony Brook Computer Science 2010
kcolton@gmail.com

Last edited by colt527 : 28-01-2005 at 22:42.