Skip to content

Latest commit

Β 

History

History
37 lines (26 loc) Β· 958 Bytes

File metadata and controls

37 lines (26 loc) Β· 958 Bytes

πŸ”„ ConvertUnitAmount()

πŸ“Œ Purpose

Convert an amount of a unit to another of the same or different type.


🧾 Inputs

  • IngredientId β€” The ID of the ingredient being converted (used for density lookup if needed)
  • FromUnit β€” The original unit (e.g., "cup")
  • ToUnit β€” The target unit (e.g., "tbsp" or "lb")
  • Amount β€” The numeric amount to convert (e.g., 1.5)

βš™οΈ Behavior

  • If both FromUnit and ToUnit are the same type (e.g., volume β†’ volume like tbsp β†’ cup),
    β†’ Use UnitConversionVolume lookup table
  • If crossing unit types (e.g., cup β†’ lb),
    β†’ Use IngredientDensityBridge (requires IngredientId)
  • Return the converted amount as a single numeric value

βœ… Example

Convert:

  • IngredientId = "CHEDDAR"
  • FromUnit = "cup"
  • ToUnit = "lb"
  • Amount = 1

Result:

  • Uses density bridge: 1 cup of cheddar = 0.25 lb
  • Return: 0.25