A minimalist calculator web application that clones the Windows Calculator design with advanced decimal handling.
- Basic Operations: Addition (+), Subtraction (−), Multiplication (×), Division (÷)
- Advanced Operations: Modulo (%), Reciprocal (1/x), Square (x²), Square Root (√x)
- Memory Functions: MC, MR, M+, M−, MS, M▼ (History)
- Function Buttons: DEL, C, CE
The calculator uses precise arithmetic methods to avoid floating-point errors:
- Addition: Uses decimal place alignment to prevent errors like
0.1 + 0.2 = 0.30000000000000004 - Subtraction: Handles decimal subtraction with precision
- Multiplication: Accurately multiplies decimal numbers
- Division: Properly handles division with decimal results
The calculator automatically detects and formats infinite repeating decimals:
Common Repeating Decimals Detected:
1 ÷ 3 = 0.3...(displays as0.3...)2 ÷ 3 = 0.6...(displays as0.6...)1 ÷ 7 = 0.142857...(displays as0.142857...)1 ÷ 9 = 0.1...(displays as0.1...)1 ÷ 11 = 0.09...(displays as0.09...)
Detection Methods:
- Known Pattern Matching: Recognizes common repeating patterns (3, 6, 9, 142857, etc.)
- Dynamic Pattern Detection: Identifies repeating sequences of 1-8 digits that repeat at least 3 times
- Precision Limiting: For non-repeating decimals, limits display to 12 decimal places
- Large Numbers: Displays in exponential notation (e.g.,
1e+15) - Small Numbers: Displays in exponential notation for very small values
- Trailing Zeros: Automatically removes unnecessary trailing zeros
- Decimal Results: Properly formats decimal results with up to 15 decimal places
- New Calculation: Number → Operator → Number → Execute
- After Calculation Complete:
- Type Number: Starts new calculation
- Type Operator: Continues with result as first number
0.1 + 0.2 = 0.3 ✓ (not 0.30000000000000004)
0.3 - 0.1 = 0.2 ✓ (not 0.19999999999999998)
0.2 × 0.3 = 0.06 ✓
10 ÷ 3 = 3.3...
1 ÷ 7 = 0.142857...
22 ÷ 7 = 3.142857...
5 ÷ 6 = 0.83...
5 + 3 = 8
(continue) × 2 = 16
(continue) ÷ 4 = 4
- Numbers:
0-9 - Decimal:
. - Operators:
+,-,*,/,% - Calculate:
Enteror= - Clear All:
Escape - Clear Current:
Delete - Delete Last:
Backspace
calculator/
├── index.html # Main HTML file
├── css/
│ └── style.css # Styling and animations
├── js/
│ └── animation.js # Calculator logic and decimal handling
└── tailwind.config.js # Tailwind CSS configuration
preciseAdd(a, b)
- Aligns decimal places
- Converts to integers for calculation
- Divides back to get precise result
preciseSubtract(a, b)
- Similar to addition but performs subtraction
- Prevents floating-point errors
preciseMultiply(a, b)
- Counts decimal places in both numbers
- Multiplies as integers
- Adjusts decimal point in result
formatResult(num)
- Checks for repeating patterns
- Limits precision for display
- Handles exponential notation
detectRepeatingDecimal(num)
- Analyzes decimal portion with high precision (20 decimal places)
- Searches for known repeating patterns
- Dynamically detects custom repeating sequences
- Returns formatted string with ellipsis notation
- Modern browsers (Chrome, Firefox, Edge, Safari)
- Requires JavaScript enabled
- Tailwind CSS loaded via CDN
- Open
index.htmlin a web browser - Click buttons or use keyboard to input calculations
- View results with proper decimal handling
- Check history using M▼ button
Try these calculations to see repeating decimal detection:
1 ÷ 3→ Should show0.3...10 ÷ 3→ Should show3.3...1 ÷ 6→ Should show0.16...1 ÷ 7→ Should show0.142857...5 ÷ 9→ Should show0.5...22 ÷ 7→ Should show3.142857...(approximation of π)
- The calculator stores all calculations in memory (history)
- Memory functions (MC, MR, M+, M-, MS) work across calculations
- The M▼ button displays full calculation history in an alert dialog
- Repeating decimal detection works for common patterns and dynamic sequences
- Very long decimals are automatically rounded to 12 decimal places if not repeating