BigInt
BigInt は任意精度の整数を表すプリミティブ型です。Number.MAX_SAFE_INTEGER(2^53 - 1)を超える整数を正確に計算できます。
概要
BigInt は任意精度の整数を表すプリミティブ型です。Number.MAX_SAFE_INTEGER(2^53 - 1)を超える整数を正確に計算できます。
対応ブラウザ
| 機能 | デスクトップ | モバイル | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 67 | 79 | 68 | 14 | 67 | 14 | |
| BigInt() コンストラクターは長整数型の値を返します。 | 67 | 79 | 68 | 14 | 67 | 14 |
| BigInt.asIntN は静的メソッドで、長整数を符号付き整数値に丸め、その値を返します。 | 67 | 79 | 68 | 14 | 67 | 14 |
| BigInt.asUintN() は静的メソッドで、長整数を符号なし整数に丸め、その値を返します。 | 67 | 79 | 68 | 14 | 67 | 14 |
| toString() は BigInt 値のメソッドで、指定した長整数 (BigInt) 値を表す文字列を返します。末尾の "n" は文字列の一部にはなりません。 | 67 | 79 | 68 | 14 | 67 | 14 |
| valueOf() は BigInt 値のメソッドで、 BigInt オブジェクトにラップされているプリミティブ値を返します。 | 67 | 79 | 68 | 14 | 67 | 14 |
基本構文
JAVASCRIPT
const big = 9007199254740993n; // Cannot be represented as a Number
const sum = big + 1n; // 9007199254740994n
typeof big; // 'bigint'
// Cannot perform mixed operations with Number
// big + 1; // TypeError
BigInt(42) + big; // OK ライブデモ
large number. Accurate calculation
Number large number, BigInt Useaccurate to calculation..
プレビュー全画面表示
Precisioncomparison(number vs Bigint)
is accurate to and comparison.. with is errordifference that outcalculation, BigInt. with Number
プレビュー全画面表示
実務での使いどころ
-
BigInt の活用
任意精度の整数型。Number の安全な整数範囲を超える大きな数値を正確に扱える。
注意点
- 特になし。すべての主要ブラウザで安定して動作する。
アクセシビリティ
- JavaScript による動的更新時は、aria-live リージョンで変更をスクリーンリーダーに通知する。
参考リンク
Powered by web-features