光彩 / 数字转文本
将数字转换为文本
1.0.0
2021-02-16 15:20 UTC
Requires
- php: ^7.1.3|^8.0
Requires (Dev)
- phpunit/phpunit: ^7.0|^8.0|^9.0
- squizlabs/php_codesniffer: ^3.5
README
此库允许您将数字转换为文本或货币。
安装
运行以下命令将包添加到您的 composer.json 中
$ composer require splendour/number-to-text
用法
此库目前有两种数字到文本转换类型:数字和货币。要使用特定语言的特定转换器,您需要创建一个 NumberToText
类的实例,然后调用一个创建转换器新实例的方法;
数字转换器
在开始使用转换器之前,必须创建它
use Splendour\NumberToText; // create the number to text "transformer" class $transformer = new NumberToText(1); // set translation using the RFC 3066 language identifier $transformer->setTranslation('tr'); //en is default
然后可以使用 toText()
方法使用它
$transformer->toText(); // outputs "one"
示例
数字转文本
$text = new NumberToText(11);
$text->toText(); //eleven
$text = new NumberToText(1253);
$text->setTranslation('tr');
$text->toText(); //bin ikiyüzelliüç
$text = new NumberToText(6420729122344886326918433610716);
$text->toText(); //six nonillion fourhundredtwenty octillion sevenhundredtwentynine septillion onehundredtwentytwo sextillion threehundredfortyfour quintillion eighthundredeightysix quadrillion twohundredseventytwo trillion onehundredsixtyeight billion sixhundredsixteen million fourhundredtwentyfour thousand onehundredsixtyeight
数字转货币
$money = new NumberToText(4563.24);
$money->toMoney('dollars', 'cents') //four thousand fivehundredsixtythree dollars twentyfour cents
贡献
感谢您考虑贡献。
许可协议
该项目是开源软件,采用 MIT 许可协议。