asNum method
Retrieves the numeric value associated with the key
. If the key does not exist or the value cannot be parsed as a number, returns the def
value.
key
The key in the map to retrieve the value from.
def
The default value to return if the key is not found or the value cannot be parsed. Defaults to 0
.
Returns: The numeric value associated with the key
or def
if not found or cannot be parsed.
Implementation
num asNum(String key, {num def = 0}) {
if (keys.contains(key)) {
return this[key].toString().asNum(def: def);
}
return def;
}