PHPackages                             snoeren-development/laravel-currency-casting - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. snoeren-development/laravel-currency-casting

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

snoeren-development/laravel-currency-casting
============================================

Cast currency attributes, stored as integer, to floats automatically.

v1.10.0(1y ago)526.6k↓43.6%3MITPHPPHP ^8.2CI passing

Since Apr 23Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/snoeren-development/laravel-currency-casting)[ Packagist](https://packagist.org/packages/snoeren-development/laravel-currency-casting)[ Docs](https://github.com/snoeren-development/laravel-currency-casting)[ Fund](https://bunq.me/SnoerenDevelopment)[ RSS](/packages/snoeren-development-laravel-currency-casting/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (28)Used By (0)

Laravel Currency Casting
========================

[](#laravel-currency-casting)

[![Latest version on Packagist](https://camo.githubusercontent.com/94ff97dd2d71609cd954ea438efe760a76635fc93226464ad776f7831a884fe1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736e6f6572656e2d646576656c6f706d656e742f6c61726176656c2d63757272656e63792d63617374696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/snoeren-development/laravel-currency-casting)[![Software License](https://camo.githubusercontent.com/3093db0e7fe2d49a3a0d4633ad99b87997c19c1bc210ebbcbf218bab42346af6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736e6f6572656e2d646576656c6f706d656e742f6c61726176656c2d63757272656e63792d63617374696e673f7374796c653d666c61742d737175617265)](LICENSE)[![Build status](https://camo.githubusercontent.com/d3432ba0b236c243130ab4a45b6053c1894481a2ee38188efa3a7b3d2161367b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736e6f6572656e2d646576656c6f706d656e742f6c61726176656c2d63757272656e63792d63617374696e672f7068702e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/snoeren-development/laravel-currency-casting/actions)[![Downloads](https://camo.githubusercontent.com/47346fab423eed282153007d2a713358715a38b83cb4c086a76d4ffade5c3eb4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736e6f6572656e2d646576656c6f706d656e742f6c61726176656c2d63757272656e63792d63617374696e673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/snoeren-development/laravel-currency-casting)

This package adds a Laravel model cast. This way you can cast any attribute that stores a currency, with an integer value in the database, to a float automatically!

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

[](#installation)

You can install the package using Composer:

```
composer require snoeren-development/laravel-currency-casting
```

### Requirements

[](#requirements)

This package requires **at least** PHP 8.2 and Laravel 10.

### Usage

[](#usage)

Store your currency as an integer value in the database. This is more accurate than storing it as a float. Add the attributes you'd like to see cast to the `casts` array and assign the `Currency` class to it. If you need more than the default 2 digits currency usually has, you can append the number of digits you need after the currency class like in the example below. Just make sure your database column can handle the larger integer it produces.

```
