// 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)
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.