Giter VIP home page Giter VIP logo

laravel-money's Introduction

Laravel Money

Latest Stable Version Total Downloads tests StyleCI codecov License

Note: This project abstracts MoneyPHP

Installation

Run the following command from you terminal:

composer require cknow/laravel-money

or add this to require section in your composer.json file:

"cknow/laravel-money": "^7.0"

then run composer update

Usage

use Cknow\Money\Money;

echo Money::USD(500); // $5.00
echo Money::USD(500, true); // $500.00 force decimals

Configuration

The defaults are set in config/money.php. Copy this file to your own config directory to modify the values. You can publish the config using this command:

php artisan vendor:publish --provider="Cknow\Money\MoneyServiceProvider"

This is the contents of the published file:

return [
    /*
     |--------------------------------------------------------------------------
     | Laravel money
     |--------------------------------------------------------------------------
     */
    'locale' => config('app.locale', 'en_US'),
    'defaultCurrency' => config('app.currency', 'USD'),
    'defaultFormatter' => null,
    'currencies' => [
        'iso' => ['RUB', 'USD', 'EUR'],  // 'all' to choose all ISOCurrencies
        'bitcoin' => ['XBT'], // 'all' to choose all BitcoinCurrencies
        'custom' => [
            'MY1' => 2,
            'MY2' => 3
        ]
    ]
];

Advanced Usage

See MoneyPHP for more information

use Cknow\Money\Money;

Money::USD(500)->add(Money::USD(500)); // $10.00
Money::USD(500)->add(Money::USD(500), Money::USD(500)); // $15.00
Money::USD(500)->subtract(Money::USD(400)); // $1.00
Money::USD(500)->subtract(Money::USD(200), Money::USD(100)); // $2.00
Money::USD(500)->multiply(2); // $10.00
Money::USD(1000)->divide(2); // $5.00
Money::USD(830)->mod(Money::USD(300)); // $2.30 -> Money::USD(230)
Money::USD(-500)->absolute(); // $5.00
Money::USD(500)->negative(); // $-5.00
Money::USD(30)->ratioOf(Money::USD(2)); // 15
Money::USD(500)->isSameCurrency(Money::USD(100)); // true
Money::USD(500)->equals(Money::USD(500)); // true
Money::USD(500)->greaterThan(Money::USD(100)); // true
Money::USD(500)->greaterThanOrEqual(Money::USD(500)); // true
Money::USD(500)->lessThan(Money::USD(1000)); // true
Money::USD(500)->lessThanOrEqual(Money::USD(500)); // true
Money::USD(500)->isZero(); // false
Money::USD(500)->isPositive(); // true
Money::USD(500)->isNegative(); // false
Money::USD(500)->getMoney(); // Instance of \Money\Money
Money::isValidCurrency('USD'); // true
Money::isValidCurrency('FAIL'); // false
Money::getISOCurrencies(); // Load ISO currencies

// Aggregation
Money::min(Money::USD(100), Money::USD(200), Money::USD(300)); // Money::USD(100)
Money::max(Money::USD(100), Money::USD(200), Money::USD(300)); // Money::USD(300)
Money::avg(Money::USD(100), Money::USD(200), Money::USD(300)); // Money::USD(200)
Money::sum(Money::USD(100), Money::USD(200), Money::USD(300)); // Money::USD(600)

// Formatters
Money::USD(500)->format(); // $5.00
Money::USD(199)->format(null, null, \NumberFormatter::DECIMAL); // 1,99
Money::XBT(41000000)->formatByBitcoin(); // \xC9\x830.41
Money::USD(500)->formatByCurrencySymbol(); // $5.00
Money::USD(500)->formatByCurrencySymbol(true); // 5.00$
Money::USD(500)->formatByDecimal(); // 5.00
Money::USD(500)->formatByIntl(); // $5.00
Money::USD(199)->formatByIntl(null, null, \NumberFormatter::DECIMAL); // 1,99
Money::USD(500)->formatByIntlLocalizedDecimal(); // $5.00
Money::USD(199)->formatByIntlLocalizedDecimal(null, null, \NumberFormatter::DECIMAL) // 1.99

// Parsers
Money::parse('$1.00'); // Money::USD(100)
Money::parseByBitcoin("\xC9\x830.41"); // Money::XBT(41000000)
Money::parseByDecimal('1.00', 'USD'); // Money::USD(100)
Money::parseByIntl('$1.00'); // Money::USD(100)
Money::parseByIntlLocalizedDecimal('1.00', 'USD'); // Money::USD(100)

Create your formatter

class MyFormatter implements \Money\MoneyFormatter
{
    public function format(\Money\Money $money)
    {
        return 'My Formatter';
    }
}

Money::USD(500)->formatByFormatter(new MyFormatter()); // My Formatter

Rules

Below is a list of all available validation rules and their function:

currency

The field under validation must be a valid currency.

Validator::make([
  'currency1' => 'USD',
  'currency2' => 'EUR',
  'currency3' => new \Money\Currency('BRL'),
], [
  'currency1' => new \Cknow\Money\Rules\Currency(),
  'currency2' => new \Cknow\Money\Rules\Currency(),
  'currency3' => 'currency',
]);

money

The field under validation must be a valid money.

Validator::make([
  'money1' => '$10.00'
  'money2' => '€10.00',
  'money3' => 'R$10,00',
  'money4' => '$10.00'
  'money5' => '€10.00',
  'money6' => 'R$10,00',
], [
  'money1' => new \Cknow\Money\Rules\Money(),
  'money2' => new \Cknow\Money\Rules\Money('EUR'), // forcing currency
  'money3' => new \Cknow\Money\Rules\Money('BRL', 'pt_BR'), // forcing currency and locale
  'money4' => 'money',
  'money5' => 'money:EUR', // forcing currency
  'money6' => 'money:BRL,pt_BR', // forcing currency and locale
]);

Casts

At this stage the cast can be defined in the following ways:

use Cknow\Money\Casts\MoneyDecimalCast;
use Cknow\Money\Casts\MoneyIntegerCast;
use Cknow\Money\Casts\MoneyStringCast;

protected $casts = [
    // cast money as decimal using the currency defined in the package config
    'money' => MoneyDecimalCast::class,
    // cast money as integer using the defined currency
    'money' => MoneyIntegerCast::class . ':AUD',
    // cast money as string using the currency defined in the model attribute 'currency'
    'money' => MoneyStringCast::class . ':currency',
    // cast money as decimal using the defined currency and forcing decimals
    'money' => MoneyDecimalCast::class . ':USD,true',
];

In the example above, if the model attribute currency is null, the currency defined in the package configuration is used instead.

Setting money can be done in several ways:

$model->money = 10; // 0.10 USD or any other currency defined
$model->money = 10.23; // 10.23 USD or any other currency defined
$model->money = 'A$10'; // 10.00 AUD
$model->money = '1,000.23'; // 1000.23 USD or any other currency defined
$model->money = '10'; // 0.10 USD or any other currency defined
$model->money = Money::EUR(10); // 0.10 EUR

When we pass the model attribute holding the currency, such attribute is updated as well when setting money:

$model->currency; // null
$model->money = '€13';
$model->currency; // 'EUR'
$model->money->getAmount(); // '1300'

Helpers

currency() // To use default currency present in `config/money.php`
currency('USD');
money(500); // To use default currency present in `config/money.php`
money(500, 'USD');

// Aggregation
money_min(money(100, 'USD'), money(200, 'USD'), money(300, 'USD')); // Money::USD(100)
money_max(money(100, 'USD'), money(200, 'USD'), money(300, 'USD')); // Money::USD(300)
money_avg(money(100, 'USD'), money(200, 'USD'), money(300, 'USD')); // Money::USD(200)
money_sum(money(100, 'USD'), money(200, 'USD'), money(300, 'USD')); // Money::USD(600)

// Parsers
money_parse('$5.00'); // Money::USD(500)
money_parse_by_bitcoin("\xC9\x830.41"); // Money::XBT(41000000)
money_parse_by_decimal('1.00', 'USD'); // Money::USD(100)
money_parse_by_intl('$1.00'); // Money::USD(100)
money_parse_by_intl_localized_decimal('1.00', 'USD'); // Money::USD(100)

Blade Extensions

@currency() // To use default currency present in `config/money.php`
@currency('USD')
@money(500) // To use default currency present in `config/money.php`
@money(500, 'USD')

// Aggregation
@money_min(@money(100, 'USD'), @money(200, 'USD'), @money(300, 'USD')) // Money::USD(100)
@money_max(@money(100, 'USD'), @money(200, 'USD'), @money(300, 'USD')) // Money::USD(300)
@money_avg(@money(100, 'USD'), @money(200, 'USD'), @money(300, 'USD')) // Money::USD(200)
@money_sum(@money(100, 'USD'), @money(200, 'USD'), @money(300, 'USD')) // Money::USD(600)

// Parsers
@money_parse('$5.00') // Money::USD(500)
@money_parse_by_bitcoin("\xC9\x830.41") // Money::XBT(41000000)
@money_parse_by_decimal('1.00', 'USD') // Money::USD(100)
@money_parse_by_intl('$1.00') // Money::USD(100)
@money_parse_by_intl_localized_decimal('1.00', 'USD') // Money::USD(100)

laravel-money's People

Contributors

a-ghorab avatar adrum avatar andreiio avatar andreschwarzer avatar cerbero90 avatar daniel-de-wit avatar davidlambauer avatar joostdebruijn avatar kevinruscoe avatar kurre avatar laravel-shift avatar lloricode avatar markahesketh avatar marwins avatar niklaslovgren avatar rez1dent3 avatar ricardogobbosouza avatar russofinn avatar shamarkellman avatar skullbock avatar subdesign avatar sudkumar avatar tiagomctavares avatar tymondesigns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-money's Issues

Error trying to install Laravel 7

TypeError

Argument 1 passed to Akaunting\Money\Currency::setCurrencies() must be of the type array, null given, called in C:\websites\laravel-tests\vendor\akaunting\money\src\Provider.php on line 22

at C:\websites\laravel-tests\vendor\akaunting\money\src\Currency.php:279
275| * @param array $currencies
276| *
277| * @return void
278| */

279| public static function setCurrencies(array $currencies)
280| {
281| static::$currencies = $currencies;
282| }
283|

1 C:\websites\laravel-tests\vendor\akaunting\money\src\Provider.php:22
Akaunting\Money\Currency::setCurrencies()

2 C:\websites\laravel-tests\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:33
Akaunting\Money\Provider::boot()

Error trying to install Laravel 7

InvalidArgumentException

$currencies must be an array or a \Money\Currencies object

at C:\websites\new1\vendor\cknow\laravel-money\src\CurrenciesTrait.php:82
78|
79| return;
80| }
81|

82| throw new InvalidArgumentException(
83| '$currencies must be an array or a \Money\Currencies object'
84| );
85| }
86|

1 C:\websites\new1\vendor\cknow\laravel-money\src\MoneyServiceProvider.php:25
Cknow\Money\Money::setCurrencies()

2 C:\websites\new1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:33
Cknow\Money\MoneyServiceProvider::boot()

How to parse correctly?

I'm trying to use the helper from the readme, money_parse('R$5,00'), and I get InvalidArgumentException with message 'Currency code should be string'.

How do I use the parse functionality?

PHP Deprecated warning

Hello,
Just tinkering around with the package, per the documentation, this should (and indeed returning) without a warning:

echo Money::parseByDecimal('1.00', 'USD');
1.00 $

But it is returning with a warning:

>>> echo Money::parseByDecimal('1.00', 'USD');
<warning>PHP Deprecated:  Passing a currency as string is deprecated since 3.1 and will be removed in 4.0. Please pass a Money\Currency instance instead. in /Users/main/Code/book/vendor/moneyphp/money/src/Parser/DecimalMoneyParser.php on line 55</warning>
‏1.00 $⏎
>>> 

Any reason what am I missing?

£ should not have a space after it

In the UK, we don't put a space after the pound sign.

Looking at the code, the only way to make this configurable would be to remove the hardcoded space in getPrefix() and make the space part of the prefix strings.

Breaks package discovery on App Engine

Greetings!

First, thanks for putting this together. It really cleans up MoneyPHP and makes a nice, uniform way of working with it in Laravel.

After much debugging, I've narrowed down a deployment failure to App Engine as a failure of php artisan package:discover --ansi during the build process. If I remove this package, then the deployment works just fine.

The best I can tell from the build failure output is this hunk:

Step #1 - "builder": In Compiler.php line 36:
Step #1 - "builder":                                       
Step #1 - "builder":   Please provide a valid cache path.  

Please keep in mind that this only occurs if this package is installed. If I remove the package, then this error does not occur. This makes me think that this package is attempting to access something from the cache before things are ready.

This may have something to do with how App Engine introduces environment variables. In a normal Laravel setup the .env file provides the environment data and is loaded in, then accessible via the env. App Engine, conversely, has an app.yaml file that loads data as environment variables — rather than being loaded upfront. This still works, however, as the env function checks for environment variables as well.

If I find anything further I'll be sure to add a comment.

Make `\Cknow\Money\Money` object from `\Money\Money` object

I plan to do a PR for #19, but it the mean time i'm using the conversion features from moneyPHP directly.

The issue is that they return a Money\Money object, which breaks the downstream type hints for \Cknow\Money\Money.

I propose to add a static constructor that returns an instance of this library's class from the base money object. That way, I can massage it back to the right type :)

\Cknow\Money\Money::fromMoney(\Money\Money $money): \Cknow\Money\Money

Will PR shortly if that's ok :)

XBT currency not exists in this repository

Hi
I need to use XBT currency, but when I set in config currency to XBT I get error that xbt is not supported by current repository.
Do I need to change something to use xbt?

ReflectionException - Class blade.compiler does not exist - L5.2

Hi, I'm receiving this error on Laravel 5.2

Resolved by registering BladeExtensions at MoneyServiceProvider with the following line

BladeExtensions::register(app('view')->getEngineResolver()->resolve('blade')->getCompiler());

Do you want me to create a pull request for this?

When serialized by laravel the formatted amount with currency symbol dissappears

When using this amazing package when ever I return my amount as a money object as json I only ever get..

{amount: "29000", currency: "USD"}

I would also like to get the format with the actual currency symbol i.e. $29.00 so it could return

{amount: "29000", currency: "USD", formatted: "$29.00"}

Forgive me if i'm not using the package correctly.

Laravel 6.x Support

Hello,

I'm trying to install it on Laravel v6.18.40, but an error says :
cknow/laravel-money v6.0.0 requires illuminate/support ^7.0|^8.0

Thanks

how to add custom currency?

Hi, is there any way to create and add our own currency into the Facade?
I am looking for something like this:

// define the currency
class CST extends Currency
{
    ...
}

// some other settings

// use the currency with the Facade
echo Money::CST($amount);

ServiceProvider not found

PT_BR:
E aí, tudo bem? Cara, tentei usar o pacote de vocês hoje mas não consegui.

Class 'ClickNow\Money\MoneyServiceProvider' not found

Em meu composer.json:

"require": {
    "php": ">=5.6.4",
    "laravel/framework": "5.3.*",
    "laravelcollective/html": "^5.3",
    "doctrine/dbal": "^2.5",
    "paragonie/random_compat": "~1.4",
    "cviebrock/eloquent-sluggable": "4.1",
    "cknow/laravel-money": "~0.1.0"
},

Ele já não encontra a classe quando vai rodar o php artisan optimize após a instalação.

Sugestões? Parece ser algo simples.
Abraços!

--

EN:
Hello, what's up? Man, I tried to use your package today but I didn't get it.

Class 'ClickNow\Money\MoneyServiceProvider' not found

On my composer.json:

"require": {
    "php": ">=5.6.4",
    "laravel/framework": "5.3.*",
    "laravelcollective/html": "^5.3",
    "doctrine/dbal": "^2.5",
    "paragonie/random_compat": "~1.4",
    "cviebrock/eloquent-sluggable": "4.1",
    "cknow/laravel-money": "~0.1.0"
},

It already doesn't find the class when running php artisan optimize after the installation.

Suggestions? Seems to be something simple.
Cheers!

Api

Hot to return value in string but use in json?

In my tests, return a Money Object.

Trait method conflict

There is currently an issue when trying to retrieve the currency from a Cknow\Money\Money instance:

$money = new Money('100', new Currency('EUR'));

return $money->getCurrency();

The expected returning value would be an instance of Money\Currency holding EUR as currency code. However we get the string USD because CurrenciesTrait::getCurrency() is called instead.

formatByFormatter

Hi,

Can you maybe please add an example to the docs of how to work with a formatter be used with the "formatByFormatter" method? Can a custom formatter be defined?

  1. All the currencies are against the value so on a table with lots of data it makes it hard to read.

CA$6,010,873.71

It would already help if a space could be inserted eg.

CA$ 6,010,873.71

  1. is there a way to format the value to be just:

6,010,873.71

when using the formatByDecimal() the values are formatted like:

6010873.71

Thanks for the package!

error Class

Add App;
ClickNow\Money\MoneyServiceProvider::class,

Add My Class;
use ClickNow\Money\Money;

Example:
return Money::BRL(500);

Error:
Class 'ClickNow\Money\Money' not found

How to parse €10,00

Hi,

This works for en_US locale:

use Money\Currencies\ISOCurrencies;
use Money\Parser\IntlMoneyParser;

$currencies = new ISOCurrencies();

$numberFormatter = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
$moneyParser = new IntlMoneyParser($numberFormatter, $currencies);

$money = $moneyParser->parse('$1.00');

echo $money->getAmount(); // outputs 100

But for it_IT with comma as decimal separator it doesn't. I know this is just the Laravel integration of the library but maybe someone can help. Thanks.

My config file should be ok:

return [
    'locale' => config('app.locale', 'it_IT'),
    'currency' => config('app.currency', 'EUR'),
];

formatSimple()?

I'm looking for the functionality as described to be found in formatSimple(). But it's seems to be gone...

[Request] Add class docblocks for better IDE compatibility

It would be beneficial if you could add some docblocks for classes to enable better autocompletion and documentation in IDE's like PHPStorm. It would also clear out some warnings made by PHPStorm about my code.

Here's a few screenshots to clear up what I mean:
without-docblocks-1
without-docblocks-2
with-docblocks-1
with-docblocks-2

I could help out and make a PR, but I don't know when I have time to do it. Okay, I managed to find some time to make a small PR, see #9

Get amount formatted correctly, but without prefix/suffix

I am missing a method to format a number into the local format. The closest I can get is using format, but it includes the currency (suffix/prefix) but I only want the amount formatted.

money('1,5', 'DKK', true)->format() // gives me: 1,50kr. I only want: 1,50

This method could do the trick:

/**
 * format amount.
 *
 * @return string
 */
public function formatAmount()
{
    $negative = $this->isNegative();
    $value = $this->getValue();
    $amount = $negative ? -$value : $value;
    $thousands = $this->currency->getThousandsSeparator();
    $decimals = $this->currency->getDecimalMark();

    return number_format($amount, 2, $decimals, $thousands);
}

Support for Laravel 5.8

Would it be possible to adjust the composer.json to allow the support for laravel 5.8? I already made the PR but tests failed 🙈. Hopefully not a big deal.

`__callStatic` method ambiguity

Here an alias is defined for __callStatic. But this method exists in both Cknow\Money\MoneyFactory and Illuminate\Support\Traits\Macroable So in PHP8 this throws error.

Full error message: An alias was defined for method __callStatic(), which exists in both Cknow\ Money\MoneyFactory and Illuminate\Support\Traits\Macroable. Use Cknow\Money \MoneyFactory::__callStatic or Illuminate\Support\Traits\Macroable::__callS tatic to resolve the ambiguity

how to format price to int

Hi i know that i should find a solution by myself, but i digged in documentation without a result.

What i'm asking is there a way to delete the decimal numbers. For exemple instead of having an ouput like this: $10.00 i would rather have this: $10

Another question i'm not using the dollar currency in my current projet. So how to pass the product price and avoid the conversion from cents to dollar as used in dollar currency. To give an exemple:

Money::USD(500) // output $5.00  
Money::MAD(500) //output 5.00 MAD which is incorrect (it should be 500.00 MAD)

Incorrect output for IRR currency

with USA currency everything works well until it is changed to other currencies like IRR,

we can call it poor support for other currencies.

image

Config and Blade Extensions not working

Hi,
I correctly installed the package, but I have these errors:
This is my config/money.php:

'locale' => 'it_IT',
'currency' => 'EUR',

but I always get the dollar symbol if I use money(value) in blade file.

Other than that, in blade file @money(value) does not work.

Eloquent casting to Money object

Laravel 7 has custom casts! Woohoo!

I propose adding a custom cast to this package to handle saving money values to the database.

Example:

protected $casts = [
	// Cast integer value from the DB into money object
	'money_fixed' => FixedMoneyCast::class . : 'USD',
	// Cast integer value with dynamic currency from DB (using `currency` field for currency)
	'money_dynamic' => DynamicMoneyCast::class,
	// Cast integer value with dynamic currency from DB (using specific field for currency)
	'money_dynamic' => DynamicMoneyCast::class, . ':base_currency',
// Cast integer value with dynamic currency from DB (using specific field for currency, with a default)
	'money_dynamic' => DynamicMoneyCast::class, . ':base_currency,USD',
];

Happy to take a crack at a PR :)

Where does the default currency come from?

I'm integrating this package within another Laravel package I'm working on. I don't want the user to manage two config files. So I'm setting the config for laravel-money from within my package's service provider. This works great.

protected function setMoneyConfig(): void
{
    $locale = Config::get('my_package.locale');
    $currency = Config::get('my_package.currency');

    Config::set('money.locale', $locale);
    Config::set('money.defaultCurrency', $currency);
}

I tried the money() helper. According to the config if should use the default currency set in the config.

money(500); // To use default currency present in `config/money.php`

But money(500)->currency() still returns USD. I'm expecting it to return the currency I set in my service provider. So now I'm not quite sure if everything works properly under the hood.

parsing of $5,555.95

I'm trying to parse and normalize for db storage a value of "$5,555.95" to parse that into 5555.95

I tried many variations of money('$5,555.95','USD')->parse() (Based on what I was reading from moneyphp docs), but it continues to through an error:

[InvalidArgumentException]
Invalid integer part $5,555. Invalid digit found

Any suggestions how to resolve this?

Format functions doesn't read precision parameter

The format() function doesn't get the actual precision parameter from the config file, here:

$value = number_format($amount, 2, $decimals, $thousands);

Changing the above line to:

$value = number_format($amount, $this->currency->getPrecision(), $decimals, $thousands);

That correctly reads the precision parameter, which is necessary for cents fraction and different subunit values.

A nice addition would be to remove leading zeros when using precision bigger than 2, for instance, if precision is 4, showing 0,5555 is ok, but 0,5500 should still be trimmed to 0,55.

Missing Information about the Project

Hi Team,
I am just curious about the project. What this project does? Did not get the main purpose of this project, Why this project is created? Thanks

How to change or disable symbol in blade

Hi,

Thank you for the awesome package.

In south Africa our currency is ZAR (Rand), however we display pricing like this: R100.00 and not ZAR100.00

Using blade, how do I force the symbol 'R' or just return the decimal value so I can add the 'R' myself?

Thanks!

How to change default locale?

I tried to change locale in config/app.php but Money($amount) still returned BRL as it's currency.

Any possible method?

Idea: add custom currencies

It would be awesome to add a capability to define app currencies list, including custom currencies:

use Money\Currency;
use Money\Currencies\CurrencyList;
use Money\Currencies\AggregateCurrencies;
use Money\Currencies\BitcoinCurrencies;
use Money\Currencies\ISOCurrencies;

$customCurrencies = new CurrencyList([
    'MY1' => 2,
]);

$currencies = new AggregateCurrencies([
    new BitcoinCurrencies(),
    new ISOCurrencies(),
    $customCurrencies
]);

This list user could inject once and all available currencies would be checked from this list, also when calling getAllCurrencies in Cast.

symbol_first no longer in v3

Hi, I have been using this package since it was at version 1,
In version 1, "cknow/laravel-money": "^1.0",, the vendor publish generated a config file, config/clicknow.money.php that had something like so

'XAF' => [
        'name'                => 'CFA Franc BEAC',
        'code'                => 950,
        'precision'           => 0,
        'subunit'             => 1,
        'symbol'              => ' FCFA',
        'symbol_first'        => false,
        'decimal_mark'        => '.',
        'thousands_separator' => ',',
    ],

But the current version, "cknow/laravel-money": "^3.4", which am using does not have that again in the config, config/money.php,

All i want is to be able to set the option where the currency comes one space after the amount,

Rather than having FCFA1,200 , i want to have 1,200 FCFA ,

Is there an option to do this please,

BTW, awesome package you got there, i love it.

Conversion does not work properly on 32 bit system

I've just check it out on my app and I get this problem while converting it to money.

money( 123456789.321, 'USD', true)

dd((int) (round(($convert) ? $amount * $this->currency->getSubunit() : $amount, 0)));
outputs -539222966

File : Money\Money.php
Line No: 84

IntlLocalizedDecimalParser

Thanks for the great package!

One thing I noticed is that parsing using the 'IntlLocalizedDecimalParser' from the Money package isn't implemented. Any particular reason why that is?

For me would be beneficial to have this, as I have to deal with localized decimal numbers that represents a monetary value but don't have any currency symbol. At the moment I'm using the parseByDecimal method, however doesn't always work when decimal numbers have a comma for representing the decimal point.

Cheers! Sacha

Idea: attributes for currency extraction from database

When currency is stored in database in two columns:

  1. amount
  2. currency (or currency code, e.g. 810 for RUB)

It would be nice to add capability to specify from which attributes currency will be casted. It can be implemented via $attributes param for CastsAttributes::get and CastsAttributes::set methods. For example, user can extend MoneyCast class and redefine such attributes to desired.

Strange output with seperators

I get very strange output depending on what seperator I use. See:

money('1', 'DKK', true)->getAmount() // returns '100' (ØRE) as expected
money('1,5', 'DKK', true)->getAmount() // returns '150' (ØRE) as expected
money('1.5', 'DKK', true)->getAmount() // returns '1500' -> unexpected.

I guess this is because of the thousand separator, but it seems like a bug to me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.