Does anybody know the equivalent command to Floor a number. Floor is a command used in Blitz Basic, and it's meaning is:
Rounds downward, i.e. in the direction of -Infinity
Floor( 1.75 ) ...... 1.0
Floor( -1.75 ) ...... -2.0
Cheers and many thanks,
Clyde.
There's not really an equivelant but strangely int(value) seems to do the trick but i dont know why it's not rounding to the nearest instead.
dim a as single=-1.1
dim b as single
b=int(a)
print "int(1.1)=";b
a=1.9
b=int(a)
print "int(1.9)=";b
sleep
Cheers for that Dude :)
Thanks,
Clyde.
I suspect that the int() command doesnt actually preform any rounding it just removes the info after the decimal point, something I recall reading about in a C++ book were they suggested adding 0.5 to a number before converting it.
If that's the case then surely negative floats would also be rounded toward 0
Would it be hard to make a function in FB, to do the job of rounding of floor / ceil as in BB.
Would of thought, they'd be an equivalent preset command. It's also strange about int not rounding to the nearest whole number.
well you can do it by adding/subtracting like tindragon mentioned then converting from float to int and back again but that's probably not the best way but if you want to see other ways then maybe have a look at this, http://www.koders.com/assembler/fidBC013758A0628BCCF9B0980CB8732BFE5B0E559E.aspx.
if you dont use int and just have
dim f as single,i as integer
i=f
then it rounds to the nearest
int(float_value) seems to do the trick for floor and for ceil you'd just do int(float_value+1.0) though.
Check CINT command too, it rounds to nearest integer.
cint(-1.75 ) = -2
cint(1.75 ) = 2
cint(1.3) = 1
cint(1.6 ) = 2
Cool cheers StoneMonkey And Rbraz. Will do in ze morning.
Many thanks,
Clyde.