martinjoiner / ordinal-number
将数字转换为可读的序数形式,例如 'first'、'second' 或甚至 'Three thousand five hundred sixty first'
v1.0.0
2016-12-19 16:49 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 5.5.*
This package is not auto-updated.
Last update: 2024-09-28 19:15:01 UTC
README
这是一个PHP包,用于将数字转换为可读的序数句子,例如 'first'、'second' 或甚至 'Three thousand five hundred and sixty first'
最新版本支持1-9999范围内的数字。
安装
推荐通过Composer安装
composer require martinjoiner/ordinal-number
请参阅Packagist上的库页面 https://packagist.org.cn/packages/martinjoiner/ordinal-number
使用示例
// Tell our code to use the namespace use MartinJoiner\OrdinalNumber\OrdinalNumber; // The following line will output 'three hundred seventy eighth' print OrdinalNumber::convert( 378 ); // The following line will output 'three hundred and seventy eighth' print OrdinalNumber::convert( 378, true ); // The following line will output 'Three hundred and seventy eighth' (notice capitalised) print OrdinalNumber::convert( 378, true, true );
convert()方法参数
必需参数
- num {integer} 要转换的数字(范围在1-9999之间)
可选参数
- appendAnd {boolean} - 默认: false - 如果数字大于101,则在最后两部分之前放置单词 'and'(例如,One hundred and first)。添加以支持英语的美国和欧洲版本。
- titleCase {boolean} - 默认: false - 首字母大写
要查看一些工作示例,只需运行index.php
测试
测试是用PHPUnit编写的 https://phpunit.de/
phpunit --bootstrap vendor/autoload.php tests/OrdinalNumberTest