toNumber function

num? toNumber(
  1. dynamic value, {
  2. bool showException = false,
})

Implementation

num? toNumber(dynamic value, {bool showException = false}) {
  if (value == null) {
    return null;
  }
  if (value is num) {
    return value;
  }
  if (value is! String) {
    if (showException) {
      throw Exception('Only String and num allowed.');
    }
    return null;
  }
  return double.tryParse(value.toString().trim());
}