A local nutrition tracking app powered by AI
YuHeng provides a robust system for handling different nutritional and weight units, allowing users to track their intake in the units they are most comfortable with.
1 kcal ≈ 4.184 kJ1 g ≈ 0.035274 ozThe core conversion logic is centralized in lib/units.ts.
Internally, YuHeng stores all data in base units:
kcalgramsConversions only happen during input (when saving to the database) and output (when displaying to the user).
The system provides several helper functions for clean UI rendering:
displayEnergy(value, unit): Returns a rounded number based on the preferred unit.displayWeight(value, unit): Returns a number with appropriate decimal places (1 for oz, 0 for g).formatEnergy / formatWeight: Returns a string with the value and unit unit suffix.Users can switch their preferred units in the Settings page. Changing these settings only affects how data is displayed; existing logs in the database remain consistent because they are stored in base units.