Unit Price Calculator - Problem
You are shopping at a grocery store and need to calculate the unit price of an item to compare value between different products.
Given the total price of an item and its quantity, calculate the unit price (price per single unit) rounded to 2 decimal places.
Formula: unit_price = total_price / quantity
Input: Two numbers - total price and quantity
Output: Unit price rounded to 2 decimal places
Input & Output
Example 1 — Basic Calculation
$
Input:
totalPrice = 12.50, quantity = 5
›
Output:
2.50
💡 Note:
Unit price = 12.50 ÷ 5 = 2.50 per item
Example 2 — Rounding Required
$
Input:
totalPrice = 10.00, quantity = 3
›
Output:
3.33
💡 Note:
Unit price = 10.00 ÷ 3 = 3.333... rounds to 3.33
Example 3 — Exact Division
$
Input:
totalPrice = 8.00, quantity = 4
›
Output:
2.00
💡 Note:
Unit price = 8.00 ÷ 4 = 2.00 exactly
Constraints
- 0.01 ≤ totalPrice ≤ 1000.00
- 1 ≤ quantity ≤ 1000
- Result rounded to exactly 2 decimal places
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code