Overview
The Discount Calculator is one of Numix’s core features, designed to help businesses accurately calculate discounted prices with support for multiple discount types, cascading discounts, and tax calculations.Percentage Discounts
Calculate discounts as a percentage of the original price
Fixed Amount
Apply discounts as fixed monetary amounts
Multiple Discounts
Apply primary and additional discounts sequentially
Tax Calculation
Calculate taxes on the discounted subtotal
Discount Modes
The calculator supports two distinct discount calculation modes:Percentage Mode
In percentage mode, discounts are applied as percentages of the current price. This mode uses cascading discount logic, where each subsequent discount is applied to the already-discounted price.discount_provider.dart
Cascading Discount Example: A $100 item with 20% + 10% discounts:
- After first discount: 100 × 0.20) = $80
- After second discount: 80 × 0.10) = $72
- Total savings: 30!)
Fixed Amount Mode
In fixed amount mode, discounts are applied as absolute monetary values. Multiple fixed discounts are simply added together.discount_provider.dart
Calculation Flow
The calculator follows a precise sequence:Parse and Validate Input
All inputs are safely parsed using
double.tryParse() to prevent crashes from invalid input.discount_provider.dart
Apply Discount Logic
Discounts are applied according to the selected mode (percentage or fixed amount), with proper validation at each step.
Calculate Tax
Tax is calculated on the discounted subtotal, not the original price:
discount_provider.dart
Validation Rules
The calculator enforces strict business rules to prevent invalid calculations:Negative Value Protection
Negative Value Protection
All values (price, discounts, tax) must be non-negative.
Percentage Range Validation
Percentage Range Validation
In percentage mode, discounts cannot exceed 100%.
Fixed Discount Ceiling
Fixed Discount Ceiling
In fixed amount mode, total discounts cannot exceed the original price.
Input Fields
The calculator accepts four input values:| Field | Type | Required | Description |
|---|---|---|---|
| Original Price | Number | Yes | The starting price before any discounts |
| Primary Discount | Number | Yes | The first discount to apply (% or fixed amount) |
| Additional Discount | Number | No | Optional second discount (% or fixed amount) |
| Tax Percentage | Number | No | Tax rate to apply to the discounted price |
Output Values
After calculation, the following values are available:- Subtotal: Price after all discounts, before tax
- Saved Amount: Total monetary value saved from discounts
- Tax Amount: Tax calculated on the subtotal
- Final Price: Subtotal plus tax (the amount customer pays)
State Persistence
All inputs are automatically saved to device storage using SharedPreferences:discount_provider.dart
Usage Example
Scenario: A store offers 20% off a $100 item, plus an additional 10% off for loyalty members, with 8% sales tax.Enter Values
- Original Price:
100 - Primary Discount:
20(percentage mode) - Additional Discount:
10 - Tax:
8
Related Features
Sales Price Calculator
Calculate optimal pricing with markup or margin
Mathematical Precision
Learn how Numix ensures calculation accuracy