Floating Point to Integer Rounding
Positron8 · Revision 4.0.6.5 · PDF page 31
Assigning a floating point variable to an integer type will be truncated to the nearest value by default. For example:
Device = 16F1829 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsout
Dim MyDword as Dword
Dim MyFloat as Float = 3.9
MyDword = MyFloat
HRsoutLn Dec MyDword ' Transmit the integer result 3
Stop
The variable MyDword will hold the value of 3.
If rounding to the nearest integer value is required, use the fRound function.
