Sgn 函式Sgn function

傳回 Variant (整數) 表示數字的正負號。Returns a Variant (Integer) indicating the sign of a number.

語法Syntax

Sgn(數字)Sgn(number)

必要的_數字_引數可以是任何有效的數值運算式The required number argument can be any valid numeric expression.

傳回值Return values

如果 數字If number is Sgn 傳回Sgn returns
大於 0Greater than zero 11
等於 0Equal to zero 00
小於 0Less than zero -1-1

註解Remarks

數字 引數的正負號會決定 Sgn 函數的傳回值。The sign of the number argument determines the return value of the Sgn function.

範例Example

這個範例會使用 Sgn 函數判斷數字的正負號。This example uses the Sgn function to determine the sign of a number.

Dim MyVar1, MyVar2, MyVar3, MySign
MyVar1 = 12: MyVar2 = -2.4: MyVar3 = 0
MySign = Sgn(MyVar1)    ' Returns 1.
MySign = Sgn(MyVar2)    ' Returns -1.
MySign = Sgn(MyVar3)    ' Returns 0.

另請參閱See also

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.