指数関数 (指数) 表記または固定小数点表記法を使用して数値のストリング表現を取得します。
パラメータ | 説明 |
---|---|
precision | 表記の小数点以下の部分の桁数。デフォルトは 0 です。 |
戻り値 | 説明 |
---|---|
string | 指数関数表記または固定小数点表記法での数値のストリング値。 |
function p(stuff) {
print("<<<" + stuff + ">>>");
}
var n : Number;
try {
n = new Number(543.21);
p(n.toPrecision(0)); // Prints <<<543>>>
p(n.toPrecision(1)); // Prints <<<543.2>>>
p(n.toPrecision(2)); // Prints <<<543.21>>>
p(n.toPrecision(3)); // Prints <<<543.210>>>
p(n.toPrecision(4)); // Prints <<<543.2100>>>
} catch(e) {
p("Error = " + e);
}
この例では、指数関数フォーマットの数値をさまざまな精度で印刷します。
function p(stuff) {
print("<<<" + stuff + ">>>");
}
var n : Number;
try {
n = new Number(54321E-99);
p(n.toPrecision(0)); // Prints <<<5E-95>>>
p(n.toPrecision(1)); // Prints <<<5.4E-95>>>
p(n.toPrecision(2)); // Prints <<<5.43E-95>>>
p(n.toPrecision(3)); // Prints <<<5.432E-95>>>
p(n.toPrecision(4)); // Prints <<<5.4321E-95>>>
} catch(e) {
p("Error = " + e);
}
この例では、指数関数フォーマットの数値をさまざまな精度で印刷します。
function p(stuff) {
print("<<<" + stuff + ">>>");
}
var n : Number;
try {
n = new Number(54321E99);
p(n.toPrecision(0)); // Prints <<<5E103>>>
p(n.toPrecision(1)); // Prints <<<5.4E103>>>
p(n.toPrecision(2)); // Prints <<<5.43E103>>>
p(n.toPrecision(3)); // Prints <<<5.432E103>>>
p(n.toPrecision(4)); // Prints <<<5.4321E103>>>
} catch(e) {
p("Error = " + e);
}