of_the_double_string static method
Tokens
of_the_double_string(
- String token_string, {
- required int decimal_places,
})
Implementation
static Tokens of_the_double_string(String token_string, {required int decimal_places}) {
token_string = token_string.trim();
if (token_string == '') {
throw Exception('must be a number');
}
List<String> token_string_split = token_string.split('.');
if (token_string_split.length > 2) {
throw Exception('invalid number.');
}
BigInt whole_tokens = BigInt.parse(token_string_split[0]);
BigInt tokens_less_than_1 = BigInt.from(0);
if (token_string_split.length == 2) {
String token_string_decimal_places = token_string_split[1];
if (token_string_decimal_places.length > decimal_places) {
throw Exception('Max ${decimal_places} decimal places');
}
while (token_string_decimal_places.length < decimal_places) {
token_string_decimal_places = '${token_string_decimal_places}0';
}
tokens_less_than_1 = BigInt.parse(token_string_decimal_places);
}
Tokens tokens = Tokens(quantums: (whole_tokens * BigInt.from(pow(10, decimal_places))) + tokens_less_than_1, decimal_places: decimal_places);
return tokens;
}