Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mahanrahmati/libcalculator
A mathematical expression evaluator for Dart that handles arithmetic operations, parentheses, decimal numbers, and proper operator precedence with precise calculations.
https://github.com/mahanrahmati/libcalculator
Last synced: 9 days ago
JSON representation
A mathematical expression evaluator for Dart that handles arithmetic operations, parentheses, decimal numbers, and proper operator precedence with precise calculations.
- Host: GitHub
- URL: https://github.com/mahanrahmati/libcalculator
- Owner: MahanRahmati
- License: bsd-3-clause
- Created: 2024-12-13T21:38:38.000Z (10 days ago)
- Default Branch: main
- Last Pushed: 2024-12-13T21:44:16.000Z (10 days ago)
- Last Synced: 2024-12-13T22:28:18.584Z (10 days ago)
- Language: Dart
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# LibCalculator
A mathematical expression evaluator for Dart that handles arithmetic operations with proper precedence rules.
## Features
- Evaluates mathematical expressions with support for:
- Basic arithmetic operations (+, -, \*, /)
- Parentheses for expression grouping
- Decimal numbers
- Proper operator precedence
- Clean error handling for invalid expressions
- Automatic result formatting (integers or decimals)
- Precise calculations with rounding to 10 decimal places## Getting started
Add this package to your project's dependencies:
```yaml
dependencies:
libcalculator: ^1.0.0
```Then run:
```bash
dart pub get
```## Usage
Simple usage example:
```dart
import 'package:libcalculator/libcalculator.dart';void main() {
final calculator = Calculator();// Basic arithmetic
print(calculator.calculate('2 + 3')); // Output: 5// Expression with parentheses
print(calculator.calculate('2 * (3 + 4)')); // Output: 14// Decimal numbers
print(calculator.calculate('10 / 3')); // Output: 3.3333333333// Complex expressions
print(calculator.calculate('(2.5 + 3.5) * (4 - 1) / 2')); // Output: 9
}
```