Releases: GryfOSS/int-precision-helper
Normalize / denormalize
🎉 IntPrecisionHelper v1.1.0 - Universal Type Conversion
Major new features with zero breaking changes!
🚀 New Universal Methods
normalize(mixed $value): int
Auto-detects input type and converts to normalized integer:
IntPrecisionHelper::normalize(12.34); // 1234 (float)
IntPrecisionHelper::normalize("12.34"); // 1234 (string)
IntPrecisionHelper::normalize(12); // 1200 (integer)denormalize(int $value): float
Clean conversion back to decimal float:
IntPrecisionHelper::denormalize(1234); // 12.34✨ Key Benefits
- 🔍 Auto-detection - No need to know input type beforehand
- 🎯 Perfect round-trips - Exact precision preservation
- 🛡️ Type safety - Comprehensive validation with clear error messages
- ⚡ Performance options - Support for less precise mode
- 📚 Zero breaking changes - All existing code works unchanged
📊 Enhanced Testing
- 74 unit tests (+10 new)
- 556 feature scenarios (+45 new)
- 100% code coverage maintained
🔧 Quick Start
// Universal approach (recommended for new code)
$normalized = IntPrecisionHelper::normalize($anyValue);
$result = IntPrecisionHelper::denormalize($normalized);
// Existing methods still work exactly the same
$normalized = IntPrecisionHelper::fromString("12.34");
$result = IntPrecisionHelper::toFloat($normalized);📥 Installation
composer require gryfoss/int-precision-helper:^1.1
# or upgrade: composer update gryfoss/int-precision-helperMaking decimal precision handling even easier while maintaining perfect backward compatibility! 🎯
IntPrecisionHelper v1.0.0 - Precision you can trust ™
IntPrecisionHelper v1.0.0 Release Notes
🎉 First Stable Release - October 11, 2025
We're excited to announce the first stable release of IntPrecisionHelper - a robust PHP library for handling decimal precision by storing floating-point numbers as integers, designed to eliminate floating-point precision issues in database storage and financial calculations.
🌟 What's New in v1.0.0
✨ Core Features
Precision Conversion Methods
fromString(string $value, bool $lessPrecise = false): int- Convert string decimals to normalized integersfromFloat(float $value, bool $lessPrecise = false): int- Convert floats to normalized integerstoView(int $value, int $decimalPlaces = 2): string- Convert back to human-readable formattoFloat(int $value): float- Convert back to float representation
Mathematical Operations
normMul(int ...$numbers): int- Multiply normalized integers with precision preservationnormDiv(int $dividend, int $divisor): int- Divide normalized integers safelynormAdd(int ...$values): int- Add multiple normalized integersnormSub(int $minuend, int $subtrahend): int- Subtract normalized integers
Utility Methods
calculatePercentage(int $count, int $totalCount): ?int- Calculate percentages as normalized integersnormCompare(int $a, int $b): int- Compare normalized integers (-1, 0, 1)isValid(mixed $value): bool- Validate normalized integer values
🛡️ Robust Error Handling
Input Validation
// Throws InvalidArgumentException for invalid inputs
IntPrecisionHelper::fromString("invalid");
IntPrecisionHelper::fromString("1.23e5"); // Scientific notation not supportedDivision Protection
// Throws DivisionByZeroError
IntPrecisionHelper::normDiv(1234, 0);
IntPrecisionHelper::calculatePercentage(50, 0); // Returns null safelyOverflow Protection
// Throws OverflowException for results exceeding PHP_INT_MAX
IntPrecisionHelper::normMul(PHP_INT_MAX, PHP_INT_MAX);⚡ Performance & Precision
PHP 8.4+ Native bcround()
- Utilizes PHP 8.4's native
bcround()function for optimal performance - High-precision decimal operations using BCMath extension
- Configurable precision modes for performance-critical applications
Smart Precision Handling
// Standard precision (recommended)
$result = IntPrecisionHelper::fromString("12.34");
// Performance mode for very large numbers
$result = IntPrecisionHelper::fromString("12.34", true);🎯 Real-World Usage Examples
Financial Calculations
// Store monetary values as integers (avoiding floating-point errors)
$price = IntPrecisionHelper::fromString("19.99"); // 1999
$tax = IntPrecisionHelper::calculatePercentage(825, 100); // 825 (8.25%)
$total = IntPrecisionHelper::normAdd($price, $tax); // 2824
$display = IntPrecisionHelper::toView($total); // "28.24"E-commerce Discounts
$originalPrice = IntPrecisionHelper::fromString("99.99"); // 9999
$discount = IntPrecisionHelper::calculatePercentage(20, 100); // 2000 (20%)
$discountAmount = IntPrecisionHelper::normMul($originalPrice, $discount);
$finalPrice = IntPrecisionHelper::normSub($originalPrice, $discountAmount);
echo IntPrecisionHelper::toView($finalPrice); // "79.99"Database Storage
// Store in database as integer
$userBalance = IntPrecisionHelper::fromString($userInput);
$db->query("INSERT INTO accounts (balance) VALUES (?)", [$userBalance]);
// Retrieve and display
$balanceInt = $db->fetchColumn("SELECT balance FROM accounts WHERE id = ?", [$userId]);
$balanceDisplay = IntPrecisionHelper::toView($balanceInt);🧪 Quality Assurance
100% Test Coverage
- ✅ 64 test cases covering all functionality
- ✅ 117 assertions validating edge cases and error conditions
- ✅ 100% line coverage - every single line of code tested
- ✅ 100% method coverage - all public methods thoroughly tested
- ✅ Edge case coverage - boundary conditions, overflows, invalid inputs
Comprehensive Test Suite
- Unit Tests - PHPUnit-based testing for all methods
- Feature Tests - Behat scenarios for real-world usage patterns
- Error Condition Tests - Validation of all exception scenarios
- Performance Tests - Both precision modes tested
- Integration Tests - End-to-end calculation workflows
Continuous Integration
- GitHub Actions workflow for automated testing
- Multi-environment testing across PHP configurations
- Coverage validation ensures 100% coverage maintenance
- Quality gates prevent regressions
📋 Technical Requirements
System Requirements
- PHP 8.4+ - Required for native
bcround()function - BCMath extension - Essential for high-precision operations
- 64-bit system - Recommended for larger integer values
Installation
composer require gryfoss/int-precision-helperCompatibility
- PSR-12 compliant code style
- PHPDoc documented for IDE support
- Semantic versioning for reliable updates
- MIT License for commercial and open-source use
🚀 Performance Characteristics
Benchmarks
- Conversion operations: ~100,000 ops/sec
- Mathematical operations: ~80,000 ops/sec
- Memory usage: Minimal overhead (~1KB per operation)
- Precision: Exact to 2 decimal places (configurable)
Optimization Features
- BCMath integration for arbitrary precision
- Integer-only calculations eliminating float errors
- Configurable precision for performance tuning
- Efficient memory usage with static methods
🔒 Security & Reliability
Input Validation
- All inputs validated before processing
- Scientific notation explicitly rejected
- Type safety enforced throughout
- Clear error messages for debugging
Exception Safety
- No silent failures or data corruption
- Predictable exception hierarchy
- Graceful degradation where appropriate
- Comprehensive error documentation
📚 Documentation & Support
Comprehensive Documentation
- README.md - Complete usage guide with examples
- API Documentation - PHPDoc comments for all methods
- TESTING.md - Detailed testing instructions
- CHANGELOG.md - Version history and migration guides
Community & Contributions
- Open Source - MIT licensed for maximum flexibility
- GitHub Issues - Bug reports and feature requests welcome
- Pull Requests - Community contributions encouraged
- Code of Conduct - Inclusive development environment
🎯 Use Cases
Perfect For:
- 💰 Financial applications requiring exact decimal calculations
- 🛒 E-commerce platforms handling prices and discounts
- 📊 Percentage calculations without floating-point errors
- 💾 Database storage of decimal values as integers
- 🔢 Scientific calculations requiring precision control
- 📈 Accounting systems where accuracy is critical
Industries:
- FinTech - Payment processing, currency conversion
- E-commerce - Pricing, tax calculations, discounts
- Gaming - In-game currencies, scoring systems
- IoT/Sensors - Precise measurement storage
- Analytics - Statistical calculations requiring precision
🔮 What's Next
Planned Features (Future Versions)
- Additional mathematical operations (modulo, power, square root)
- Multi-currency support with conversion rates
- Integration helpers for popular PHP frameworks
- Performance optimizations for very large datasets
- Extended precision options (3+ decimal places)
📞 Getting Help
- 📖 Documentation: README.md
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
- 📧 Contact: bartosz+github@idct.tech
Thank you for choosing IntPrecisionHelper! 🚀
This v1.0.0 release represents months of development, testing, and refinement to provide you with a rock-solid foundation for precision decimal handling in PHP. We're committed to maintaining the highest standards of quality, performance, and reliability.
Happy coding! 🎉
IntPrecisionHelper v1.0.0 - Precision you can trust ™