Dev.to WebDev 🛠 Dev 👁 2

Supplement cost per serving: the formula and the label edge cases

Disclosure: written by the Health World Web editorial team, who publish healthworldweb.com and the sister site healthysupplements.us. No affiliate links. A supplement label has two numbers that people mix up: the servin

Disclosure: written by the Health World Web editorial team, who publish healthworldweb.com and the sister site healthysupplements.us. No affiliate links.

A supplement label has two numbers that people mix up: the serving size and the servings per container. If you build anything that parses or compares labels, model both, and never store "capsules per bottle" as if it were servings.

The cost formula

cost_per_serving = final_price / servings_per_container
cost_per_active_unit = cost_per_serving / amount_per_serving

Use the final price after shipping and tax if you can. Use the same unit for the active amount, for example mg of elemental magnesium, not mg of the compound.

Edge cases worth handling

  • Serving size of 2 or more capsules.
  • Amount in mcg on one bottle and mg on another (1 mg = 1,000 mcg).
  • Vitamin D in IU versus mcg (1 mcg = 40 IU).
  • Proprietary blends that list only a total weight.

We keep a free browser calculator at healthworldweb.com and plain-language label notes at healthysupplements.us.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.