NumberUtils extension

Extensions on num for real-world utility operations.

on

Properties

digitCount int

Available on num, provided by the NumberUtils extension

Returns the number of digits in the integer part.
no setter
isDouble bool

Available on num, provided by the NumberUtils extension

Returns true if this number has a fractional part.
no setter
isFibonacci bool

Available on num, provided by the NumberUtils extension

Returns true if this number is a Fibonacci number.
no setter
isInteger bool

Available on num, provided by the NumberUtils extension

Returns true if this number has no fractional part.
no setter
isPositive bool

Available on num, provided by the NumberUtils extension

Returns true if this number is positive (> 0).
no setter
isPrime bool

Available on num, provided by the NumberUtils extension

Returns true if this number is prime. Only meaningful for positive integers.
no setter
isZero bool

Available on num, provided by the NumberUtils extension

Returns true if this number is zero.
no setter
reversed int

Available on num, provided by the NumberUtils extension

Reverses the digits of this number.
no setter

Methods

clampTo(num min, num max) num

Available on num, provided by the NumberUtils extension

Clamps this number to the range min..max.
factorial() int

Available on num, provided by the NumberUtils extension

Returns the factorial of this number (must be a non-negative integer).
gcd(int other) int

Available on num, provided by the NumberUtils extension

Returns the greatest common divisor of this and other.
isInRange(num min, num max) bool

Available on num, provided by the NumberUtils extension

Returns true if this number is in the range min..max (inclusive).
lcm(int other) int

Available on num, provided by the NumberUtils extension

Returns the least common multiple of this and other.
lerp(num to, double t) double

Available on num, provided by the NumberUtils extension

Linear interpolation from this number to to by factor t (0..1).
normalize(num min, num max) double

Available on num, provided by the NumberUtils extension

Normalizes this number to the range 0..1 given min and max.
pad(int width, {String padChar = '0'}) String

Available on num, provided by the NumberUtils extension

Pads this number's string representation to width with padChar.
percentage(num total, {int precision = 1}) String

Available on num, provided by the NumberUtils extension

Returns this number as a percentage of total, formatted to precision decimal places.
randomList({int min = 0, int max = 100}) List<num>

Available on num, provided by the NumberUtils extension

Returns a list of this random numbers in min..max.
roundTo(int decimals) double

Available on num, provided by the NumberUtils extension

Rounds this number to decimals decimal places.
safeDivide(num divisor, {double fallback = 0.0}) double

Available on num, provided by the NumberUtils extension

Divides this number by divisor, returning fallback if divisor is zero.
sumOfDigits() int

Available on num, provided by the NumberUtils extension

Returns the sum of digits of this number (integer part only).
swapSign() num

Available on num, provided by the NumberUtils extension

Negates this number.
toBinary() String

Available on num, provided by the NumberUtils extension

Converts this number to its binary string representation.
toCompact({int decimals = 1}) String

Available on num, provided by the NumberUtils extension

Returns a compact string representation (K, M, B, T).
toCurrencyString({String delimiter = ',', int precision = 2, String symbol = ''}) String

Available on num, provided by the NumberUtils extension

Converts to a currency-formatted string.
toDegrees() double

Available on num, provided by the NumberUtils extension

Converts radians to degrees.
toDuration() Duration

Available on num, provided by the NumberUtils extension

Converts this number (seconds) to a Duration.
toFileSize({int decimals = 1}) String

Available on num, provided by the NumberUtils extension

Formats this number (bytes) as a human-readable file size string.
toHex({bool upperCase = false}) String

Available on num, provided by the NumberUtils extension

Converts this number to its hexadecimal string representation.
toOctal() String

Available on num, provided by the NumberUtils extension

Converts this number to its octal string representation.
toOrdinal() String

Available on num, provided by the NumberUtils extension

Returns the ordinal string for this number ("1st", "2nd", "3rd", etc.).
toPrecision([int precision = 2]) String

Available on num, provided by the NumberUtils extension

Converts to a string with precision decimal places, stripping trailing zeros (e.g. 1.50'1.5', 1.00'1').
toRadians() double

Available on num, provided by the NumberUtils extension

Converts degrees to radians.
toRoman() String

Available on num, provided by the NumberUtils extension

Converts this number to a Roman numeral string (1–3999).
toWords() String

Available on num, provided by the NumberUtils extension

Converts this integer (0–999,999,999) to its English word representation.