php 货币格式化,用于货币格式化和转换的Laravel包

  • Post author:
  • Post category:php


Currency formatting and conversion package for Laravel.

68747470733a2f2f706f7365722e707567782e6f72672f616b61756e74696e672f6d6f6e65792f762f737461626c652e737667
68747470733a2f2f706f7365722e707567782e6f72672f616b61756e74696e672f6d6f6e65792f642f746f74616c2e737667
68747470733a2f2f7472617669732d63692e636f6d2f616b61756e74696e672f6d6f6e65792e737667
68747470733a2f2f7374796c6563692e696f2f7265706f732f3131323132313530382f736869656c643f7374796c653d666c6174266272616e63683d6d6173746572
68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616b61756e74696e672f6d6f6e65792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572
68747470733a2f2f706f7365722e707567782e6f72672f616b61756e74696e672f6d6f6e65792f6c6963656e73652e737667

This package intends to provide tools for formatting and conversion monetary values in an easy, yet powerful way for Laravel projects.

Why not use the moneyphp package?

Because moneyphp uses the intl extension for number formatting. intl extension isn’t present by default on PHP installs and can give different results in different servers.

Getting Started

1. Install

Run the following command:

composer require akaunting/money

2. Register (for Laravel < 5.5)

Register the service provider in config/app.php

Akaunting\Money\Provider::class,

3. Publish

Publish config file.

php artisan vendor:publish –tag=money

4. Configure

You can change the currencies information of your app from config/money.php file

Usage

use Akaunting\Money\Currency;

use Akaunting\Money\Money;

echo Money::USD(500); // ‘$5.00’ unconverted

echo new Money(500, new Currency(‘USD’)); // ‘$5.00’ unconverted

echo Money::USD(500, true); // ‘$500.00’ converted

echo new Money(500, new Currency(‘USD’), true); // ‘$500.00’ converted

Advanced

$m1 = Money::USD(500);

$m2 = Money::EUR(500);

$m1->getCurrency();

$m1->isSameCurrency($m2);

$m1->compare($m2);

$m1->equals($m2);

$m1->greaterThan($m2);

$m1->greaterThanOrEqual($m2);

$m1->lessThan($m2);

$m1->lessThanOrEqual($m2);

$m1->convert(Currency::GBP, 3.5);

$m1->add($m2);

$m1->subtract($m2);

$m1->multiply(2);

$m1->divide(2);

$m1->allocate([1, 1, 1]);

$m1->isZero();

$m1->isPositive();

$m1->isNegative();

$m1->format();

Helpers

money(500, ‘USD’)

currency(‘USD’)

Blade Directives

@money(500, ‘USD’)

@currency(‘USD’)

Changelog

Please see Releases for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email security@akaunting.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.