fromDouble static method
Converts a double value and a currency into an API compatible PaymentAmount
Implementation
static PaymentAmount fromDouble(String currency, double n) {
if (!n.isFinite) {
throw Exception('Non finite number $n');
}
if (!isInSafeRange(n)) {
throw UnsafeNumberException(n);
}
var splitted = n.toString().split('.');
var wholes = splitted[0];
var somes = splitted.length > 1 ? splitted[1] : "";
var value = int.parse(wholes + somes);
return PaymentAmount(
currency: currency.toUpperCase(),
value: value,
exponent: value == 0 ? 0 : somes.length);
}