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
Returnstrueif this number has a fractional part.no setter - isFibonacci → bool
-
Available on num, provided by the NumberUtils extension
Returnstrueif this number is a Fibonacci number.no setter - isInteger → bool
-
Available on num, provided by the NumberUtils extension
Returnstrueif this number has no fractional part.no setter - isPositive → bool
-
Available on num, provided by the NumberUtils extension
Returnstrueif this number is positive (> 0).no setter - isPrime → bool
-
Available on num, provided by the NumberUtils extension
Returnstrueif this number is prime. Only meaningful for positive integers.no setter - isZero → bool
-
Available on num, provided by the NumberUtils extension
Returnstrueif 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 rangemin..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 andother. -
isInRange(
num min, num max) → bool -
Available on num, provided by the NumberUtils extension
Returnstrueif this number is in the rangemin..max(inclusive). -
lcm(
int other) → int -
Available on num, provided by the NumberUtils extension
Returns the least common multiple of this andother. -
lerp(
num to, double t) → double -
Available on num, provided by the NumberUtils extension
Linear interpolation from this number totoby factort(0..1). -
normalize(
num min, num max) → double -
Available on num, provided by the NumberUtils extension
Normalizes this number to the range 0..1 givenminandmax. -
pad(
int width, {String padChar = '0'}) → String -
Available on num, provided by the NumberUtils extension
Pads this number's string representation towidthwithpadChar. -
percentage(
num total, {int precision = 1}) → String -
Available on num, provided by the NumberUtils extension
Returns this number as a percentage oftotal, formatted toprecisiondecimal places. -
randomList(
{int min = 0, int max = 100}) → List< num> -
Available on num, provided by the NumberUtils extension
Returns a list ofthisrandom numbers inmin..max. -
roundTo(
int decimals) → double -
Available on num, provided by the NumberUtils extension
Rounds this number todecimalsdecimal places. -
safeDivide(
num divisor, {double fallback = 0.0}) → double -
Available on num, provided by the NumberUtils extension
Divides this number bydivisor, returningfallbackif 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 withprecisiondecimal 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.