{
  "id": "unit-price",
  "version": "e1c68621ef98",
  "status": "published",
  "name": "Unit Price Calculator",
  "question": "What is the unit price?",
  "summary": "Works out the price per ounce, pound, gram, liter, or item of a product, and compares two sizes or brands to show the better buy and how much cheaper it is.",
  "category": "everyday-life",
  "subcategory": "money-and-shopping",
  "url": "https://www.acalculator.org/everyday-life/unit-price-calculator",
  "markdown": "https://www.acalculator.org/everyday-life/unit-price-calculator.md",
  "kind": "function",
  "method": "unit price = price ÷ size; the better buy is the item with the lower price per unit after converting both sizes to one unit",
  "assumptions": [
    "Sizes convert exactly: 1 lb = 16 oz = 453.59237 g, 1 gal = 4 qt = 8 pt = 128 fl oz = 3.785411784 L.",
    "Weights (oz, lb, g, kg), volumes (fl oz, pt, qt, gal, mL, L) and counts (ct) cannot be compared with each other.",
    "Unit prices are exact from the typed decimals; two count as the same when they differ by at most one billionth of the higher one."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "priceA": {
        "title": "Item A price",
        "description": "The price of the first item.",
        "type": "number",
        "x-unit": "USD",
        "minimum": 0,
        "maximum": 1000000000
      },
      "sizeA": {
        "title": "Item A size",
        "description": "How much the first item holds, in the unit chosen next.",
        "type": "number",
        "minimum": 0.000001,
        "maximum": 1000000000
      },
      "unitA": {
        "title": "Item A unit",
        "description": "The unit of the size: a weight, a volume, or a count of items (ct).",
        "type": "string",
        "enum": [
          "oz",
          "lb",
          "g",
          "kg",
          "floz",
          "pt",
          "qt",
          "gal",
          "mL",
          "L",
          "ct"
        ]
      },
      "priceB": {
        "title": "Item B price",
        "description": "The price of the second item. Leave it empty to price one item.",
        "type": "number",
        "x-unit": "USD",
        "minimum": 0,
        "maximum": 1000000000
      },
      "sizeB": {
        "title": "Item B size",
        "description": "How much the second item holds, in the unit chosen next.",
        "type": "number",
        "minimum": 0.000001,
        "maximum": 1000000000
      },
      "unitB": {
        "title": "Item B unit",
        "description": "The unit of the size: a weight, a volume, or a count of items (ct).",
        "type": "string",
        "enum": [
          "oz",
          "lb",
          "g",
          "kg",
          "floz",
          "pt",
          "qt",
          "gal",
          "mL",
          "L",
          "ct"
        ]
      }
    }
  },
  "outputs": {
    "perA": {
      "label": "Item A price per unit",
      "description": "Item A’s price ÷ its size: the price per one of its units.",
      "format": "money"
    },
    "perB": {
      "label": "Item B price per unit",
      "description": "Item B’s price ÷ its size: the price per one of its units.",
      "format": "money"
    },
    "perBinA": {
      "label": "Item B per item A’s unit",
      "description": "When the units differ: item B’s price per one of item A’s units, for a like-for-like comparison.",
      "format": "money"
    },
    "cheaper": {
      "label": "Better buy",
      "description": "The item with the lower price per unit, or both when they are the same.",
      "format": "text"
    },
    "saving": {
      "label": "Cheaper per unit by",
      "description": "How much less the better buy costs per unit, as a percent of the other item’s unit price.",
      "format": "percent"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "priceA": 3.49,
      "sizeA": 12,
      "unitA": "oz",
      "priceB": 5.99,
      "sizeB": 24,
      "unitB": "oz"
    },
    "outputs": {
      "perA": 0.29083333333333333,
      "perB": 0.24958333333333332,
      "cheaper": "Item B",
      "saving": 14.183381088825215
    },
    "text": "Item A, $3.49 for 12 oz, costs $0.2908 per oz."
  },
  "examples": [
    {
      "given": {
        "priceA": 3.49,
        "sizeA": 12,
        "unitA": "oz",
        "priceB": 5.99,
        "sizeB": 24,
        "unitB": "oz"
      },
      "expect": {
        "perA": 0.29083333333333333,
        "perB": 0.24958333333333335,
        "cheaper": "Item B",
        "saving": 14.183381088825215
      },
      "source": "NIST SP 1181, Unit Pricing Guide (2025 edition): the unit price is the price per unit of measure (https://www.nist.gov/publications/nist-sp-1181-unit-pricing-guide-best-practice-approach-unit-pricing-2025-ed); hand calculation in content.mdx; Python 3 (fractions) cross-check in docs/progress/WP-56.md"
    },
    {
      "given": {
        "priceA": 4.99,
        "sizeA": 1,
        "unitA": "lb",
        "priceB": 2.79,
        "sizeB": 500,
        "unitB": "g"
      },
      "expect": {
        "perA": 4.99,
        "perB": 0.00558,
        "perBinA": 2.5310454246,
        "cheaper": "Item B",
        "saving": 49.277646801603204
      },
      "source": "NIST SP 811 (2008), Appendix B: 1 lb = 453.59237 g exactly; hand calculation in content.mdx; Python 3 (fractions) cross-check in docs/progress/WP-56.md"
    },
    {
      "given": {
        "priceA": 2.5,
        "sizeA": 64,
        "unitA": "floz",
        "priceB": 3.99,
        "sizeB": 1,
        "unitB": "gal"
      },
      "expect": {
        "perA": 0.0390625,
        "perBinA": 0.031171875,
        "cheaper": "Item B",
        "saving": 20.2
      },
      "source": "NIST SP 811 (2008), Appendix B: 1 gal = 128 fl oz; hand calculation in content.mdx"
    },
    {
      "given": {
        "priceA": 6,
        "sizeA": 12,
        "unitA": "ct",
        "priceB": 9,
        "sizeB": 18,
        "unitB": "ct"
      },
      "expect": {
        "perA": 0.5,
        "perB": 0.5,
        "cheaper": "Both the same"
      },
      "source": "hand calculation in content.mdx: $6 ÷ 12 = $9 ÷ 18 = $0.50 an item"
    }
  ],
  "sources": [
    "NIST SP 1181, Unit Pricing Guide: A Best Practice Approach to Unit Pricing (2025 edition), and NIST Handbook 130, Uniform Unit Pricing Regulation: the unit price is the price per unit of measure (per ounce, pound, 100 g, and so on), for comparing package sizes. https://www.nist.gov/publications/nist-sp-1181-unit-pricing-guide-best-practice-approach-unit-pricing-2025-ed",
    "NIST SP 811 (2008), Appendix B: 1 lb = 453.59237 g, 1 oz = 28.349523125 g, 1 US gallon = 3.785411784 L = 128 fl oz, all exact."
  ],
  "related": [
    "tip",
    "gas",
    "electricity-cost"
  ],
  "changelog": []
}
