定制 gerardojbaez/money 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gerardojbaez/money

最新稳定版本:v0.3.1

Composer 安装命令:

composer require gerardojbaez/money

包简介

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

README 文档

README

Money is a small PHP library that helps you format numbers to currencies, including INR (Indian Rupee) and NGN (Nigrian Naira). It's a simple alternative to money_format().

Example:

<?php

$money = new Gerardojbaez\Money\Money(12.99, 'USD')
$money->format(); // RESULT: $12.99

// You can also use the included helper:
moneyFormat(12.99, 'USD'); // RESULT: $12.99

Content

Installation

Pull this package through Composer (file composer.json)

{
    "require": {
        "gerardojbaez/money": "0.*"
    }
}

Then run

composer update
<?php

require 'vendor/autoload.php';

use Gerardojbaez\Money\Money;

$money = new Money(100);
$money->format();

Basic Usage

Currencies Supported

ARS, AMD, AWG, AUD, BSD, BHD, BDT, BZD, BMD, BOB, BAM, BWP, BRL, BND, CAD, KYD, CLP, CNY, COP, CRC, HRK, CUC, CUP, CYP, CZK, DKK, DOP, XCD, EGP, SVC, EUR, GHC, GIP, GTQ, HNL, HKD, HUF, ISK, INR, IDR, IRR, JMD, JPY, JOD, KES, KWD, LVL, LBP, LTL, MKD, MYR, MTL, MUR, MXN, MZM, NPR, ANG, ILS, TRY, NZD, NOK, PKR, PEN, UYU, PHP, PLN, GBP, OMR, RON, ROL, RUB, SAR, SGD, SKK, SIT, ZAR, KRW, SZL, SEK, CHF, TZS, THB, TOP, AED, UAH, USD, VUV, VEF, VEB, VND, ZWD.

Formatting Using Helper Function

<?php

// USD
echo moneyFormat(100); // RESULT: $100.00
echo moneyFormat(10000); // RESULT: $10,000.00

// INR
echo moneyFormat(100, 'INR'); // RESULT: र100
echo moneyFormat(1000000, 'INR'); // RESULT: र10,00,000

Formatting Using Class

<?php

$money = new Gerardojbaez\Money\Money(1000000, 'INR');

echo $money->format(); // RESULT: र10,00,000
echo $money; // The same as using $money->format()

echo $money->amount(); // RESULT: 10,00,000

Customizing Currency Format

To use a custom format, create an instance of the Currency class with the desired currency and use the setters (se the example below) to apply the desired format. Use this instance with the Money class (or the helper) to finally format the number.

For example:

$currency = new Gerardojbaez\Money\Currency('USD');
$currency->setPrecision(3);
$currency->setThousandSeparator('.');
$currency->setDecimalSeparator(',');
$currency->setSymbolPlacement('after');

$money = new Gerardojbaez\Money\Money(1200.9, $currency);
echo $money; // RESULT: 1.200,900$ (example)

// OR
echo moneyFormat(1200.9, $currency);

Parse String

<?php

echo Money::parse('$1,200.90', 'USD')->toDecimal(); // RESULT: 1200.9

Get Currency Information

$currency = new Gerardojbaez\Money\Currency('USD');
echo $currency->getTitle(); // US Dollar
echo $currency->getCode(); // USD
echo $currency->getSymbol(); // $
echo $currency->getSymbolPlacement(); // after (before|after amount)
echo $currency->getPrecision(); // 2 (number of decimals)
echo $currency->getThousandSeparator(); // ,
echo $currency->getDecimalSeparator(); // .

Get All Supported Currencies

$currencies = Gerardojbaez\Money\Currency::getAllCurrencies();

// Result Example:
[
	'ARS' => [
		'code' => 'ARS'
		'title' => 'Argentine Peso'
		'symbol' => null
		'precision' => 2
		'thousandSeparator' => ','
		'decimalSeparator' => '.'
		'symbolPlacement' => 'before'
	]

	'AMD' => [
		'code' => 'AMD'
		'title' => 'Armenian Dram'
		'symbol' => null
		'precision' => 2
		'thousandSeparator' => '.'
		'decimalSeparator' => ','
		'symbolPlacement' => 'before'
	]

	...

License

This package is free software distributed under the terms of the MIT license.

统计信息

  • 总下载量: 270.68k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 57
  • 点击次数: 2
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 56
  • Watchers: 3
  • Forks: 21
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固