Real Software Forums

converting VB Int() to RB
Page 1 of 1

Author:  torrid [ Tue Nov 22, 2011 3:42 pm ]
Post subject:  converting VB Int() to RB

I have a VBfunction i am converting which uses this....basically does not round but return just integer part of a number....

I have looked in documentation but am not the equivalent the Floor function?

Author:  Jason_Adams [ Tue Nov 22, 2011 5:08 pm ]
Post subject:  Re: converting VB Int() to RB

Yup. :)

Floor rounds down (ignoring all but the integer, as it were); ceiling rounds up invariably.

Author:  classone [ Thu Nov 24, 2011 5:40 am ]
Post subject:  Re: converting VB Int() to RB

You don't need floor in this instance.
Dim mvar as double = 3.14
dim mInt as integer = mvar

MInt now equals 3

Author:  Jason_Adams [ Fri Nov 25, 2011 9:46 am ]
Post subject:  Re: converting VB Int() to RB

I'm sure it's unnecessary, but I tend not to trust myself to such conversions. It wouldn't surprise me if — say in the switch to LLVM — the conversion altered from an implicit floor, to rounding. Albeit, I'm sure there's a convention for this, but I like to be safe and explicit.

But, I'm starting to delve in to development preferences. ;)

Author:  andrekui [ Thu Jan 26, 2012 4:12 pm ]
Post subject:  Re: converting VB Int() to RB

Sure you need to use Floor() because Int() in VB delivers the greatest whole number that is smaller than the float-value that is within it's brackets.
In RB:
dim mint as integer = 3.14 gives as result 3
and for negative values:
dim mint as integer = -3.14 gives as result -3

but in VB:
Int(3.14) gives as result 3 (this is equal to the result in RB)
Int(-3.14) gives as result -4 (instead of -3 in RB)

Using Floor(mint) gives the same results in RB as Int(mint) in VB.

Best regards,

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group