parse static method
Parses amount
as a decimal value.
The scale
controls the number of decimal
places to be retained.
If scale
is not passe it defaults to 2.
If scale
< 0 then a FixedException will be thrown.
If the amount
isn't valid then
a FixedParseException
is thrown.
If invertSeparator
= false then we
assume '.' is the decimal place and ',' is the group separator.
If invertSeparator
= true then we
assume ',' is the decimal place and '.' is the group separator.
Implementation
static Fixed parse(
String amount, {
int scale = 2,
bool invertSeparator = false,
}) {
_checkScale(scale);
final decimalSeparator = invertSeparator ? ',' : '.';
final decoder = FixedDecoder(
/// TODO: remove the pattern from the decoder
/// as I don't think we actually need one.
/// We just need to know what char is the decimal place.
pattern: '#$decimalSeparator#',
groupSeparator: invertSeparator ? '.' : ',',
decimalSeparator: invertSeparator ? ',' : '.',
scale: scale,
);
return Fixed.fromDecimal(decoder.decode(amount), scale: scale);
}