FLOAT2SHORT

 
語法

        Result = FLOAT2SHORT(Argument)

 

操作

        將浮點數轉換為SHORT變數。

  • Argument FLOAT2SHORT函數的浮點運算元。
  • Result 接收FLOAT2SHORT函數結果的SHORT變數。

 

說明

        FLOAT2SHORT指令將一個浮點數轉換為SHORT。小數的部分會被四捨五入。如果值超過SHORT值的範圍,則會使用數值+127-128

 

範例

 

Sub Main()
   
Dim MyFloat As Float
   
Dim MyShort As Short

    MyFloat =
2.4
    MyShort =
FLOAT2SHORT(MyFloat)      ' the result is 2
    Debug "FLOAT2SHORT of 2.4 : ", MyShort, CR
    MyFloat =
2.5
    MyShort =
FLOAT2SHORT(MyFloat)      ' the result is 3
    Debug "FLOAT2SHORT of 2.5 : ", MyShort, CR
    MyFloat = -
1.0
    MyShort =
FLOAT2SHORT(MyFloat)      ' the result is -1
    Debug "FLOAT2SHORT of -1.0 : ", MyShort, CR
    MyFloat =
128.0
    MyShort =
FLOAT2SHORT(MyFloat)      ' the result is 127
    Debug "FLOAT2SHORT of 128 : ", MyShort, CR
    MyFloat = -
129.0
    MyShort =
FLOAT2SHORT(MyFloat)      ' the result is -128
    Debug "FLOAT2SHORT of -129 : ", MyShort, CR
End Sub