length method

int length()

Returns the number of characters in the string representation of this number.

For negative numbers, the leading '-' is included. For decimal numbers, the '.' is included.

Note: numbers whose absolute value is ≥ 1e21 are represented in scientific notation by Dart's toString() (e.g. 1000000000000000000000 becomes "1e+21"). For such values this method counts the characters of the scientific notation string, not the full decimal digit count. Use BigInt.from(n).toString().length if you need the true digit count for large integers.

Example:

123.length(); // Returns 3
(-123).length(); // Returns 4 (includes '-')
123.45.length(); // Returns 6 (includes '.')

NOTE: negative zero is removed when formatting. I.e. -0 becomes 0

Implementation

int length() => toString().length;