BigInt

Overview

The javascript BigInt implementation. BigInt is a built-in object that provides a way to represent whole numbers larger than 2^53-1. For more information see: BigInt (MDN).

Methods Summarized

Type
Name
Summary

Returns a BigInt limited to a signed integer value of n bits.

Returns a BigInt limited to an unsigned integer value of n bits.

Converts the BigInt value to a locale-sensitive string representation.

Converts the BigInt value to a locale-sensitive string representation.

Converts the BigInt value to a locale-sensitive string representation with the specified locales and formatting options.

Converts the BigInt value to a string using the default base (10).

Converts the BigInt value to a string in a specified base.

Returns the primitive value of the BigInt object.

Methods Detailed

asIntN(bits)

Returns a BigInt limited to a signed integer value of n bits.

Parameters

  • Number bits The number of bits to retain.

Returns: BigInt A new BigInt limited to n signed bits.

Sample

BigInt.asIntN(8, 257n);

asUintN(bits)

Returns a BigInt limited to an unsigned integer value of n bits.

Parameters

  • Number bits The number of bits to retain.

Returns: BigInt A new BigInt limited to n unsigned bits.

Sample

BigInt.asUintN(8, 257n);

toLocaleString()

Converts the BigInt value to a locale-sensitive string representation.

Returns: String The locale-sensitive string representation of the BigInt using the default locale.

Sample

BigInt(123456789123456789)toLocaleString();

toLocaleString(locales)

Converts the BigInt value to a locale-sensitive string representation.

Parameters

  • String locales A string with a BCP 47 language tag, or an array of such strings. Corresponds to the locales parameter of the Intl.NumberFormat() constructor.

Returns: String The locale-sensitive string representation of the BigInt.

Sample

BigInt(123456789123456789).toLocaleString('de-DE');

toLocaleString(locales, options)

Converts the BigInt value to a locale-sensitive string representation with the specified locales and formatting options.

Parameters

  • String locales A string with a BCP 47 language tag, or an array of such strings.

  • Object options An object with formatting options, such as `useGrouping` and `minimumIntegerDigits`.

Returns: String The locale-sensitive string representation of the BigInt using the specified locale(s) and options.

Sample

123456789012345678901234567890n.toLocaleString("de-DE", { style: 'currency', currency: 'EUR' });

toString()

Converts the BigInt value to a string using the default base (10).

Returns: String The string representation of the BigInt in base 10.

Sample

/** @type {BigInt} */
let b = 1024n;
b.toString();

toString(radix)

Converts the BigInt value to a string in a specified base.

Parameters

  • Number radix An integer between 2 and 36 that specifies the base of the returned string.

Returns: String The string representation of the BigInt in the specified base.

Sample

/** @type {BigInt} */
let b = 1024n;
b.toString(16);

valueOf()

Returns the primitive value of the BigInt object.

Returns: BigInt The primitive BigInt value.

Sample

123n.valueOf();

Last updated

Was this helpful?