ivanovsaleksejs/num-to-text
Composer 安装命令:
composer require ivanovsaleksejs/num-to-text
包简介
Converts numbers or prices to text representation in various languages. For example, 437605 becomes "four hundred thirty seven thousand six hundred five". Price class for displaying prices with currencies is also available.
README 文档
README
Converts numbers or prices to text representation in various languages.
Supported languages
Currently, library supports these languages:
- English
- Russian
- Latvian
French and Spanish are in progress.
How to install
composer require ivanovsaleksejs/num-to-text:dev-master
or add to your composer.json
{
"require": {
"ivanovsaleksejs\num-to-text": "^2.*"
}
}
and then
composer install
How to use
include __DIR__ . '/vendor/autoload.php'; use ivanovsaleksejs\NumToText\Num; use ivanovsaleksejs\NumToText\Price; echo Num::toText(1234, 'EN') . "\n"; // Echoes 'one thousand two hundred thirty four' echo Price::toText(123456.78, [['dollars', 'dollar'], ['cents', 'cent']], 'EN', true) . "\n"; // Echoes 'one hundred twenty three thousand four hundred fifty six dollars 78 cents' echo Price::toText(123456.78, [['dollars', 'dollar'], ['cents', 'cent']], 'EN') . "\n"; // Echoes 'one hundred twenty three thousand four hundred fifty six dollars seventy eight cents' echo Price::toText(1.02, [['рублей', 'рубль', 'рубля'], ['копеек', 'копейка', 'копейки']], 'RU', false, false, [0, 1]); . "\n"; // Echoes 'один рубль две копейки' // Please note, the sixth parameter specifies the gender for the integer and decimal parts of the number respectively // 0 - masculine // 1 - feminine // 2 - neutral
How to add new language
To add a language, you need to:
- extend main class NumToText (to make sure shorthand functions work, add the code of the language in caps after underscore to the name of new class, for example, NumToText_DE)
- define functions
digitToWordandtoWords - override some other functions of main class if necessary.
How to run unit tests
./vendor/bin/phpunit
统计信息
- 总下载量: 14.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 20
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-12