Skip to content
Snippets Groups Projects
Commit 10ba8b5e authored by vjrj's avatar vjrj
Browse files

Improve calculs in payments

parent 10bb9975
No related branches found
No related tags found
No related merge requests found
......@@ -144,8 +144,9 @@ String formatAmountWithLocale(String locale, double amount) {
String formatKAmount(BuildContext context, double amount) =>
formatAmount(context, amount / 100);
double parseToDoubleLocalized(String locale, String double) =>
NumberFormat.decimalPattern(locale).parse(double).toDouble();
double parseToDoubleLocalized(
{required String locale, required String number}) =>
NumberFormat.decimalPattern(locale).parse(number).toDouble();
String localizeNumber(BuildContext context, double amount) =>
NumberFormat.decimalPattern(context.locale.toString()).format(amount);
......@@ -241,3 +242,37 @@ ImageIcon get g1nkgoIcon => ImageIcon(
String get ginkgoIconLocation => assets('img/favicon.png');
String capitalize(String s) => s[0].toUpperCase() + s.substring(1);
double calculate({required String textInTerminal, required String decimalSep}) {
String operation = textInTerminal;
double sum = 0.0;
operation = operation.replaceAll(
decimalSep, '.'); // change decimal separator to a dot
final RegExp regex = RegExp(r'[\d.]+'); // regular expression to find numbers
final Iterable<Match> matches =
regex.allMatches(operation); // find all numbers in the input
for (final Match? match in matches) {
try {
if (match != null) {
final String? g1 = match.group(0);
if (g1 != null) {
sum += double.parse(g1); // add the number to the sum
}
}
} catch (e) {
// could not convert the number to a double value, ignore it
}
}
// logger(numberFormat.format(sum)); // print the formatted sum
return sum;
}
String decimalSep(BuildContext context) {
return NumberFormat.decimalPattern(context.locale.toString())
.symbols
.DECIMAL_SEP;
}
Color selectedPatternLock(BuildContext context) => Colors.red;
Color notSelectedPatternLock(BuildContext context) => Colors.amber;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment