milantarami / number-to-words
一款将数字转换为文字的甜蜜包,支持尼泊尔语和国际编号系统
v1.0.1
2021-11-11 16:40 UTC
Requires (Dev)
- orchestra/testbench: ^4.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-20 05:26:19 UTC
README
安装和设置
您可以通过composer使用此包进行安装
composer require milantarami/number-to-words
该包将自动为laravel 5.5.*及更高版本注册服务提供者。
对于以下版本,需要在config/app.php
中手动注册服务提供者
'providers' => [ /* * Package Service Providers... */ MilanTarami\NumberToWordsConverter\NumberToWordsServiceProvider::class ],
该包将自动加载laravel 5.5.*及更高版本的别名。
对于以下版本,需要在config/app.php
中手动添加别名
'aliases' => [ . . 'NumberToWords' => MilanTarami\NumberToWordsConverter\Facades\NumberToWordsFacade::class, ]
要发布配置文件到config/number_to_words.php
,请运行
php artisan vendor:publish --tag=number-to-words-config
这是配置文件的默认内容
<?php return [ /** * Add a monetary unit notation to response * [ true / false ] * default = true **/ 'monetary_unit_enable' => true, /** * supported response language * [ English (en) / Nepali [np] ] * default = en **/ 'lang' => 'en', /** * supported Response Type * [ 'string', 'array' ] * default = string **/ 'response_type' => 'string', /** * supported numbering systems * [ Nepali Numbering System (nns) / International Numbering System (ins) ] * default = nns **/ 'numbering_system' => 'nns', /** * Monetary Units for Nepal [ in English and Nepali ] * ex [ 'Dollar', 'Cent ] **/ 'monetary_unit' => [ 'en' => [ 'Rupees', 'Paisa' ], 'np' => [ 'रुपैया', 'पैसा' ] ], ];
可选参数(数组 - 可用的键和值)
基本用法
echo NumberToWords::get(123456789); //output : Twelve Crore Thirty-four Lakh Fifty-six Thousand Seven Hundred Eighty-nine Rupees and Twelve Paisa
使用配置作为可选参数的用法
示例 1
$config = [ 'monetary_unit' => [ 'Dollar', 'Cent' ], 'numbering_system' => 'ins' ]; echo NumberToWords::get(123456789.12, $config); //output : One Hundred Twenty-three Million Four Hundred Fifty-six Thousand Seven Hundred Eighty-nine Dollar and Twelve Cent
示例 2
$config = [ 'monetary_unit' => [ 'Dollar', 'Cent' ], 'numbering_system' => 'ins', 'response_type' => 'array' ]; dd(NumberToWords::get(123456789.12, $config)); //output : array:7 [▼ "integer" => 123456789 "integer_in_words" => "One Hundred Twenty-three Million Four Hundred Fifty-six Thousand Seven Hundred Eighty-nine Dollar" "point" => 12 "point_in_words" => "Twelve Cent" "original_input" => "123456789.12" "formatted_input" => "123,456,789.12" "in_words" => "One Hundred Twenty-three Million Four Hundred Fifty-six Thousand Seven Hundred Eighty-nine Dollar and Twelve Cent" ]