How the Calculators Are Built and Tested

The formulas, the rounding rules, and the tests that check them.

Formulas

Concentration (mg/mL) = vial mg ÷ water mL
Draw (mL) = dose mg ÷ concentration
U-100 syringe units = mL × 100
Doses per vial = floor(vial mg ÷ dose mg)
Water for a target (mL) = (target units ÷ 100) × vial mg ÷ dose mg
IU concentration = vial IU ÷ water mL · Somatropin: IU = mg × 3
Blend: each peptide's mg per draw = (its vial mg ÷ water mL) × draw mL
Days per vial = doses per vial ÷ doses per week × 7 · Vials needed = ceil(total doses ÷ doses per vial)
Molarity: µmol = mg ÷ MW × 1,000 · mM = µmol ÷ mL

Rounding

Calculations run at full floating-point precision. Only displayed numbers are rounded: units to 1 decimal in the headline (2 in the working), mL to 3 or 4 decimals. "Doses per vial" is rounded down with a tiny tolerance so that, for example, 0.3 ÷ 0.1 counts as 3 doses, not the 2.999… a computer would otherwise produce.

Automated tests

The test suite runs more than 520,000 checks on every run, including:

  • Hand-worked examples, such as 5 mg + 3 mL at 250 mcg = 15 units and 10 mg + 2 mL at 2 mg = 40 units.
  • 100,000 random vial, water and dose combinations compared against an independently written formula.
  • Round trips: the water planner's answer, fed back into the calculator, must return the target units exactly.
  • Checks that mg and mcg entries give identical results, that doses per vial never overcounts or undercounts, and that invalid input (zero, negative, text, a dose larger than the vial) is rejected with a clear message.
  • Separate suites for the IU, blend, vial supply, converter and molarity calculators.

All checks pass. The same code that is tested is the code that runs on every page.

What the calculators assume

  • A U-100 insulin syringe (100 units = 1 mL). The mL result is always given as well.
  • The peptide dissolves completely and evenly, and the vial contains the amount on its label.
  • The volume of the dissolved powder is negligible compared with the water added.

Found an error?

Email contact@babynamewise.com with the numbers you entered and what you expected. We fix confirmed errors and note the change here.