Skip to content

Commit 30e8878

Browse files
committed
Fix integer functions crashing with NaN and infinite values.
1 parent 45a8b72 commit 30e8878

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/src/api/extensions.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ extension RoundNum on num {
5252
/// Step 3: round(12435678.9) = 12435679
5353
/// Step 4: 12435679 / 1000 = 12435.679
5454
double roundToPrecision(int decimal) {
55+
if (isNaN || isInfinite) return toDouble();
5556
final double precision = pow(10, decimal).toDouble();
5657
return (this * precision).round() / precision;
5758
}
5859

5960
/// Returns the double as a pretty rounded double.
6061
num toPrettyPrecision(int precision) {
62+
if (isNaN || isInfinite) return this;
6163
_formatter.maximumFractionDigits = precision;
6264
return num.parse(_formatter.format(this));
6365
}

0 commit comments

Comments
 (0)