forums

TNT Basic Forums > Programming Q&A
Adding ints and floats
< Last Thread     Next Thread >
Author
Thread        Post A Reply

02-21-2004 17:58

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

When you add a floating point number smaller than 0 to a whole number, does the floating point number round, or floor?

e.g.

float x = 0.9
int y = 1

int z = x + y

print z


If this prints 1, does it mean that the floating point number has been floored? (It should print 2 if it was rounded)

Or does it mean that the point number has been set to 0?

Confused,
MapMaker

02-21-2004 18:50

Posted by:
-wyvern

Location:
Bedroom

Find more posts by -wyvern

Whats stopping you printing out x and y aswell?

02-22-2004 21:41

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

"int z=x+y" would change neither x nor y. The output of 1 means that z is floored to the nearest integer, and not that x or y was changed. Like wyvern said though, you could just print x and y to see for yourself that they are unchanged.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.