Vbscript-number-formatting-functions
提供:Dev Guides
VBScript数値書式設定関数
構文
variablename = Format_function_Name(Expression[,NumberDigAfterDec[,LeadingDig[,UseParForNegNum[,GroupDigits]]]])
説明
- 必須パラメーター Format_function_Name は、以下にリストされている数値フォーマット関数のいずれかに対応します。
- オプションのパラメーター Expression は、数値になる式に対応します。
- オプションパラメータ NumberDigAfterDec は、小数点以下の桁数に対応します。
- オプションのパラメーター LeadingDig は、小数値に先行ゼロを表示するかどうかに対応します。 以下の設定パラメーターに基づいて、3つの値のいずれかを取ります。
- オプションのパラメーター UseParForNegNum は、括弧内に負の値を配置するかどうかに対応します。 以下の設定パラメーターに基づいて、3つの値のいずれかを取ります。
- オプションのパラメーター GroupDigits は、グループ区切り文字を使用して数値をグループ化するかどうかに対応します。 以下の設定パラメーターに基づいて、3つの値のいずれかを取ります。
設定
上記のパラメータLeadingDig、UseParForNegNumおよびGroupDigits引数は、次の設定のいずれかを持つことができます-
- -2 = vbUseDefault-コンピューターの地域設定を使用する
- -1 = vbTrue-True
- 0 = vbFalse − False
例
VBScriptで使用可能なすべての数値書式設定関数を理解するには、次の例を試してください。
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
Dim num : num = -645.998651
document.write("Line 1 : " & FormatNumber(num, 3))& "<br/>"
' The UseParensForNegativeNumbers parameter is set to true.
document.write("Line 2 : " & FormatNumber (num, 3, , vbTrue))&" <br/> "
' The GroupDigits parameter is set to false.
document.write("Line 3 : " & FormatNumber (num, 3, , , vbFalse)) & "<br/>"
document.write("Line 4 : " & FormatPercent(num, 3))& "<br/>"
' The UseParensForNegativeNumbers parameter is set to true.
document.write("Line 5 : " & FormatPercent (num, 3, , vbTrue))&" <br/> "
' The GroupDigits parameter is set to false.
document.write("Line 6 : " & FormatPercent (num, 3, , , vbFalse)) & "<br/>"
</script>
</body>
</html>
上記のスクリプトを実行すると、出力は次のようになります-
Line 1 : -645.999
Line 2 : (645.999)
Line 3 : -645.999
Line 4 : -64,599.865%
Line 5 : (64,599.865%)
Line 6 : -64599.865%