Display nutritional energy in KJ with preference

This commit is contained in:
xeals
2021-10-25 17:27:47 +11:00
parent b1b770c9e5
commit 3d830a4449
3 changed files with 17 additions and 2 deletions

View File

@@ -156,6 +156,17 @@ export function roundDecimals(num) {
return +(Math.round(num + `e+${decimals}`) + `e-${decimals}`);
}
const KILOJOULES_PER_CALORIE = 4.18
export function calculateEnergy(amount, factor) {
if (getUserPreference('use_kj')) {
let joules = amount * KILOJOULES_PER_CALORIE
return calculateAmount(joules, factor) + ' kJ'
} else {
return calculateAmount(amount, factor) + ' kcal'
}
}
/*
* Utility functions to use OpenAPIs generically
* */