32 lines
975 B
Dart
32 lines
975 B
Dart
import 'dart:math';
|
|
|
|
class Utils {
|
|
static double roundToDecimalPlaces(double value, int places) {
|
|
double mod = pow(10.0, places).toDouble();
|
|
return ((value * mod).round().toDouble() / mod);
|
|
}
|
|
|
|
static double convertMgPerDlToMmolPerL(int mgPerDl) {
|
|
return Utils.roundToDecimalPlaces(mgPerDl * 0.0555, 2);
|
|
}
|
|
|
|
static int convertMmolPerLToMgPerDl(double mmolPerL) {
|
|
return (mmolPerL * 18.018).round();
|
|
}
|
|
|
|
static double calculateCarbs(
|
|
double carbsRatio, double portionSize) {
|
|
return Utils.roundToDecimalPlaces(carbsRatio * portionSize / 100, 2);
|
|
}
|
|
|
|
static double calculateCarbsRatio(
|
|
double carbsPerPortion, double portionSize) {
|
|
return portionSize > 0 ? Utils.roundToDecimalPlaces(carbsPerPortion * 100 / portionSize, 2) : 0;
|
|
}
|
|
|
|
static double calculatePortionSize(
|
|
double carbsRatio, double carbsPerPortion) {
|
|
return carbsRatio > 0 ? Utils.roundToDecimalPlaces(carbsPerPortion * 100 / carbsRatio, 2) : 0;
|
|
}
|
|
}
|