Download the PHP package ulabox/money without Composer

On this page you can find all versions of the php package ulabox/money. 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 money

Money

Build Status

PHP 7.1+ Money library using BCMath, inspired by the works of Mathias Verraes and Commerce Guys. Use 1.x series for PHP 5.4+ compatibility.

Motivation

Representing monetary values using floats is bad, you can lose precision an get weird results. It's better to use a Money value object that uses integers or BCMath. This library uses the latter.

Why another Money library? There are already tons out there!

Yup, but most of them use integers as the internal money representation and that doesn't fit our needs! Using integers is fine in most cases and much more performant, but there are times when you need sub-unit calculations. For example, gas pricing here in Spain is calculated using tenths of an Euro cent or 1.001 €. VAT calculations can also make use of this extra precision an Arbitrary Precision library like BCMath provides. We are an ecommerce and we need that extra precision, especially when calculating discounts.

Why BCMath and not GMP?

While the GMP library has better performance, its implementation in PHP lacks decimal arithmetic, it can only deal with integers. There's a proposal to add the decimal implementation to the PHP extension but that's still a work in progress.

Installation

Install the library using composer. Just run the following command

Usage

Dynamic scale

Since version 2.x, the scale of the underlying BCMath operations can be changed to suit your needs.

By default the scale of the Money class is 4. You can modify the scale when you create the Money object or when you multiply and divide. The scale is also changed when you round a number. For addition and subtraction operations, the scale used is the biggest between the 2 operands.

Integration with Doctrine 2.5

Starting from version 2.5 Doctrine supports working with Value Objects in what they call Embeddables. Bear in mind that this Money object has also a Currency VO inside, this is an embeddable inside an embeddable. Doctrine should work just fine with nested embeddables.

We suggest mapping the amount field to a decimal type. Decimal fields don't lose precision and are converted to a string type in PHP by Doctrine, exactly what we need when working with BCMath. The currency code field should be mapped to a string type. This is an example schema of a Product entity that has a price Money field.

Disclaimer

We aim to keep this library as simple as possible. That means we don't see the need of having plenty of calculation operations inside the Money class, keep that in mind if you plan to spend some valuable time in a PR! But of course, this can change as we see fit :p

We don't check the currency code against a list of valid ISO codes as we have some fake currencies in our system that use custom currency codes.


All versions of money with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1 || ^8.0
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 ulabox/money contains the following files

Loading the files please wait ....