GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - php-collective/decimal-object: Decimal handling as value object instead of plain strings or floats.

BranchesTags
Open more actions menu

Latest commit

 

History

148 Commits
148 Commits

Folders and files

NameName
Last commit message
Last commit date
.docker
.docker
 
 
.github/workflows
.github/workflows
 
 
docs
docs
 
 
src
src
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.env
.env
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.license
.license
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
compose.yaml
compose.yaml
 
 
composer.json
composer.json
 
 
phpcs.xml
phpcs.xml
 
 
phpstan.neon
phpstan.neon
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 
renovate.json
renovate.json
 
 

Repository files navigation

Decimal Object

CI codecov Latest Stable Version Minimum PHP Version PHPStan License

Decimal value object for PHP.

Documentation

https://php-collective.github.io/decimal-object/

Background

Floats cannot represent most decimal fractions exactly, which makes them unsuitable for money and other values that must add up:

var_dump(0.1 + 0.2 === 0.3); // bool(false)

Handling such values as strings works, and a value object keeps the logic for it in one place:

use PhpCollective\DecimalObject\Decimal;

$total = Decimal::create('0.1')->add('0.2');

echo $total;                  // 0.3
var_dump($total->equals('0.3')); // bool(true)

Features

  • Explicit scale handling for arithmetic, truncation and rounding.
  • Readable API: add(), greaterThan(), isZero().
  • Arithmetic, rounding, comparison and conversion.
  • Immutable.
  • Handles numbers beyond the integer and float range.
  • Calculates with PHP's bcmath extension.

Installation

Follow Installation to install the package and enable bcmath for the PHP process that runs it.

Usage

  • Getting started
  • Arithmetic
  • Precision and scale
  • Rounding
  • API reference

Integrations

  • dereuromark/cakephp-decimal as decimal type for the CakePHP ORM.

See Alternatives for how this library compares to php-decimal, brick/math and the money libraries.

Contributing

Pull requests are welcome:

  • Target master for bug fixes and backwards compatible improvements.
  • Target next (the next major version) for anything that breaks backwards compatibility.

History

The library was written in 2019 for the Spryker commerce framework and has been used there in order and price calculations since. This repository is the independently maintained continuation for the PHP ecosystem as a whole.

About

Decimal handling as value object instead of plain strings or floats.

php-collective.github.io/decimal-object/

Resources

Readme
MIT license
Activity
Custom properties

Stars

24 stars

Watchers

1 watching

Forks

4 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.