// TypeError: Cannot convert a BigInt value to a number Math.trunc(2n);
In fact, bigint values have no need for a "truncate" (or "trunc") method because:
- Bigint values are integers, and as such do not have a fraction part to "truncate" (or remove);
- Operations involving bigint values that produce a fractional result (such as division) are automatically truncated, and do not return any fractional digits.
// ES10+ const truncated = 10n / 4n; console.log(truncated); // 2n (and not 2.5n)
Hope you found this post useful. It was published . Please show your love and support by sharing this post.