Download the PHP package gryfoss/int-precision-helper without Composer

On this page you can find all versions of the php package gryfoss/int-precision-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package int-precision-helper

IntPrecisionHelper

Tests PHP Version License: MIT

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.

Installation

Purpose

This library solves common floating-point precision issues by storing decimal numbers as integers. For example:

This approach is particularly useful for:

Why PHP 8.4+ is Required

This library requires PHP 8.4 or higher because it utilizes PHP's native bcround() function, which was introduced in PHP 8.4. The bcround() function provides:

Core Functionality

Input Conversion Methods

fromString(string $value, bool $lessPrecise = false): int

Converts a string representation of a decimal number to a normalized integer.

Parameters:

Example:

Validation: Throws InvalidArgumentException for invalid input formats.

fromFloat(float $value, bool $lessPrecise = false): int

Converts a float to a normalized integer representation.

Parameters:

Example:

normalize(mixed $value, bool $lessPrecise = false): int

Universal conversion method that automatically detects input type and converts to normalized integer.

Parameters:

Examples:

Error Handling: Throws InvalidArgumentException for unsupported types (arrays, objects, etc.) or invalid string formats.

Output Conversion Methods

denormalize(int $normalizedValue): float

Converts a normalized integer back to its decimal representation as a float.

Parameters:

Example:

toView(int $value, int $decimalPlaces = 2): string

Converts a normalized integer back to a human-readable string representation.

Parameters:

Example:

toFloat(int $value): float

Converts a normalized integer back to a float representation.

Example:

Mathematical Operations

normMul(int ...$numbers): int

Performs multiplication on normalized integers while maintaining precision.

Example:

Protection: Throws OverflowException if result would exceed PHP_INT_MAX.

normDiv(int $dividend, int $divisor): int

Performs division on normalized integers with precision preservation.

Example:

Protection: Throws DivisionByZeroError if divisor is zero.

normAdd(int ...$numbers): int

Adds multiple normalized integers.

Example:

normSub(int $minuend, int $subtrahend): int

Subtracts two normalized integers.

Example:

Utility Methods

calculatePercentage(int $value, int $total): ?int

Calculates percentage as a normalized integer.

Example:

normCompare(int $a, int $b): int

Compares two normalized integers.

Returns:

Example:

isValid(mixed $value): bool

Validates if a value is a valid normalized integer.

Example:

Usage Examples

Basic Conversions

Round-Trip Conversions

Mathematical Operations

Quick Reference

New Universal Methods (Recommended)

normalize(mixed $value, bool $lessPrecise = false): int

One method to convert any supported type to normalized integer:

denormalize(int $normalizedValue): float

Convert normalized integer back to decimal float:

Type-Specific Methods (Legacy)

Input Type Method Example
String fromString("12.34") 1234
Float fromFloat(12.34) 1234
Integer $value * 100 Manual
Output Type Method Example
String toView(1234) "12.34"
Float toFloat(1234) or denormalize(1234) 12.34

When to Use Each Method

Advanced Features & Error Handling

Input Validation

The library provides comprehensive input validation with descriptive error messages:

Division by Zero Protection

All division operations are protected against division by zero:

Overflow Protection

The library detects and prevents integer overflow conditions:

Performance Modes

For performance-critical applications with very large numbers:

Breaking Changes from Original

⚠️ Important: The legacy NormMul and NormDiv methods have been removed due to PHP's case-insensitive function names conflicting with the new normMul and normDiv methods.

Migration Guide:

Configuration & Customization

Custom Precision Factor

You can customize the precision factor by extending the class:

Available Constants

Requirements

Testing & Quality Assurance

This library maintains 100% code coverage and follows rigorous testing standards to ensure reliability and precision.

Test Coverage Statistics

Running Tests Locally

Unit Tests with Coverage

Feature Tests (Behavioral Testing)

Quick Test Coverage Check

Test Categories

Unit Tests (tests/IntPrecisionHelperTest.php)

Feature Tests (features/)

Continuous Integration

The project uses GitHub Actions for automated testing:

Contributing

We welcome contributions from the community! Whether you're fixing bugs, adding features, improving documentation, or reporting issues, your help makes this library better for everyone.

How to Contribute

🐛 Reporting Issues

Found a bug or have a feature request? Please open an issue with:

🔧 Pull Requests

Ready to contribute code? We'd love your help! Please:

  1. Fork the repository and create a feature branch
  2. Write tests for any new functionality
  3. Ensure 100% coverage is maintained
  4. Follow PSR-12 coding standards
  5. Update documentation as needed
  6. Submit a pull request with a clear description

📋 Contribution Checklist

Before submitting a pull request, ensure:

🎯 Areas for Contribution

We especially welcome contributions in these areas:

💡 Feature Requests

Have an idea for a new feature? We'd love to hear it! Consider:

Development Setup

Code of Conduct

Please note that this project follows a Code of Conduct. By participating, you agree to:

Getting Help

Need help getting started or have questions?

Thank you for contributing to IntPrecisionHelper! 🚀

License

MIT License


All versions of int-precision-helper with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
ext-bcmath Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package gryfoss/int-precision-helper contains the following files

Loading the files please wait ...