Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

會傳回指示數字正負號的 Variant (Integer)。

語法

sgn ( number )

必要 數位引數 可以是任何有效的 數值運算式。

傳回值

如果 number

Sgn 傳

大於零

1

等於零

0

小於零

-1


註解

number 自 變數 的符號會決定 Sgn 函數的傳回值。

查詢範例

Expression

結果​​

SELECT Unitprice,sgn (unitprice) AS PriceSign,Discount,sgn (Discount) 為 DiscountSign FROM productSales;

傳回「單價」和「折扣」及其個別符號分別 (1 的正值、-1 的負值和零值為 0) 在 PriceSign 和 DiscountSign 數據行中。

VBA 範例

附註: 下列範例示範如何在 Visual Basic for Applications (VBA) 模組中使用此函數。 如需使用 VBA 的詳細資訊,請在 [搜尋] 旁的下拉式清單中選取 [開發人員參考],並在 [搜尋] 方塊中輸入一個或多個字詞。

此範例使用 Sgn 函數來判斷數位的符號。

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.

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×