PHPackages                             ferdiunal/money - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ferdiunal/money

ActiveLibrary

ferdiunal/money
===============

Simple yet useful money operations for php.

v1.0.4(3y ago)0111MITPHPPHP &gt;=8.1

Since Apr 7Pushed 3y agoCompare

[ Source](https://github.com/ferdiunal/money)[ Packagist](https://packagist.org/packages/ferdiunal/money)[ Docs](https://github.com/ferdiunal/money)[ RSS](/packages/ferdiunal-money/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)DependenciesVersions (6)Used By (0)

ferdiunal/money
===============

[](#ferdiunalmoney)

[![Latest Version](https://camo.githubusercontent.com/cc402787bb7ba6f0c77e34bda27dae077cba3d5c3274130100e9ddd12b3a3f9e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6665726469756e616c2f6d6f6e65792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ferdiunal/money)[![Total Downloads](https://camo.githubusercontent.com/3abfaf781e092e5d79d9fdfd0d9404c71e69ecb9d92986eef85d7285b1808eba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6665726469756e616c2f6d6f6e65792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ferdiunal/money)

This package is a fork of the sineld/money repository, with added discount and data types.

ferdiunal/money is a PHP library designed to make working with money easier! There are no static properties or methods. Any number you pass to the class will automatically be prepared for mathematical operations. The class uses , for thousands and . for decimals.

This package can be used with any framework or spaghetti application. If you encounter any issues, feel free to reach out to me by email.

Installation
------------

[](#installation)

Via Composer

```
$ composer require ferdiunal/money
```

Add the following use statement to the top of your file:

```
use Ferdiunal\Money\Money;
```

Then, start using the library!

Non-Composer Users
------------------

[](#non-composer-users)

If you are not using Composer, simply copy the Money.php file located in the src folder to your project and begin using the library. There are no extra dependencies.

### Request method aliases

[](#request-method-aliases)

Here are the parameters you can use with methods:

##### money-&gt;setDecimals(default = 2)

[](#money-setdecimalsdefault--2)

##### money-&gt;addTax(default = 18)

[](#money-addtaxdefault--18)

##### money-&gt;removeTax(default = 18)

[](#money-removetaxdefault--18)

##### money-&gt;setLocaleActive(default = false)

[](#money-setlocaleactivedefault--false)

##### money-&gt;setLocaleCode(default = TRL)

[](#money-setlocalecodedefault--trl)

##### money-&gt;setLocalePosition(default = prefix, (use "suffix" instead of reverse))

[](#money-setlocalepositiondefault--prefix-use-suffix-instead-of-reverse)

Usage Examples
--------------

[](#usage-examples)

In the following code example, a currency object is created using the `Ferdiunal\Money\Money` class. First, a currency object is created based on the specified numeric value. Then, another numeric value is added, subtracted, multiplied, and divided to the currency object. After adding a percentage-based tax, a fixed discount and a percentage-based discount are added. Finally, tax and discount are removed based on the calculations, and the currency object is formatted and retrieved using the `get()` method. The `all()` method returns the currency and tax amount as an array. The `getTax()` method returns the calculated tax amount. The `getDiscount()` method returns the calculated discount amount.

```
