Skip to content

Commit

Permalink
Migrate utils/numbers
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Zhao <[email protected]>
  • Loading branch information
dukefirehawk authored and GZGavinZhao committed Jan 15, 2022
1 parent c3a2275 commit 82c9d26
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions angular_components/lib/utils/numbers/denomination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.9

import 'package:fixnum/fixnum.dart';

/// A denomination type for defining how large values are mapped to [suffix]es
Expand All @@ -19,7 +17,7 @@ class Denomination {

/// An amount that can be multiplied by the formatted number to cancel out
/// the suffix when parsing
final int multiplier;
final int? multiplier;

/// The string suffix, if any.
final String suffix;
Expand All @@ -35,15 +33,17 @@ class Denomination {
} else if (Trillions.suffix == suffix) {
return Trillions;
} else {
return null;
// TODO(null-safety): This logic need to reevaluated
//return null;
throw ArgumentError("Unrecognized suffix [$suffix]");
}
}

/// Returns a [Denomination] based on the size of [value].
///
/// If a [max] [Denomination] is provided, will not return a denomination
/// larger than [max].
factory Denomination.fromValue(num value, [Denomination max]) {
factory Denomination.fromValue(num value, [Denomination? max]) {
if (value < Thousands.minValue || max == Hundreds) {
return Hundreds;
} else if (value < Millions.minValue || max == Thousands) {
Expand All @@ -66,7 +66,7 @@ class Denomination {
/// If [value] is a [num] or [Int64], it is converted to a double.
///
/// Otherwise, `null` is returned.
num toNum(Object value) {
num? toNum(Object value) {
if (value is num) {
return value;
} else if (value is Int64) {
Expand Down

0 comments on commit 82c9d26

Please sign in to comment.