定制 kwn/number-to-words 二次开发

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

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

kwn/number-to-words

Composer 安装命令:

composer require kwn/number-to-words

包简介

Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.

README 文档

README

CircleCI Maintainability Code Coverage Latest Stable Version

Welcome to number-to-words, a PHP utility that seamlessly transforms numeric values into their corresponding words. Effortlessly convert numbers, such as 123, into expressive and readable formats like "one hundred and twenty-three" with just a few lines of code.

Installation

Add package to your composer.json by running:

$ composer require kwn/number-to-words

Usage

There are two types of number-to-words transformation: number and currency. In order to use a relevant transformer for specific language create an instance of NumberToWords class and call a method that creates a new instance of the desired transformer;

Number Transformer

Create a transformer for specific language using the getNumberTransformer('lang') method:

use NumberToWords\NumberToWords;

// create the number to words "manager" class
$numberToWords = new NumberToWords();

// build a new number transformer using the RFC 3066 language identifier
$numberTransformer = $numberToWords->getNumberTransformer('en');

Transformer can be used by passing in numeric values to the toWords() method:

$numberTransformer->toWords(5120); // outputs "five thousand one hundred twenty"

It can be also used with a static method:

NumberToWords::transformNumber('en', 5120); // outputs "five thousand one hundred twenty"

Currency Transformer

Creating a currency transformer works just like a number transformer.

use NumberToWords\NumberToWords;

// create the number to words "manager" class
$numberToWords = new NumberToWords();

// build a new currency transformer using the RFC 3066 language identifier
$currencyTransformer = $numberToWords->getCurrencyTransformer('en');

Then it can be used passing in numeric values for amount and ISO 4217 currency identifier to the toWords() method:

$currencyTransformer->toWords(5099, 'USD'); // outputs "fifty dollars ninety nine cents"

It can be also used with a static method:

NumberToWords::transformCurrency('en', 5099, 'USD'); // outputs "fifty dollars ninety nine cents"

Note: The Currency Transformer within this library processes integers; ensure your input amounts are in whole numbers by multiplying any float values by 100 before transformation. For instance, transform 45.67 by using 4567 as the input for accurate currency conversion.

Available locale

Language Identifier Number Currency Alias
Albanian al + +
Arabic ar + +
Azerbaijani az + +
Belgian French fr_BE + -
Brazilian Portuguese pt_BR + +
Bulgarian bg + +
Czech cs + -
Danish dk + +
Dutch nl + -
English en + +
Estonian et + -
Georgian ka + +
German de + +
French fr + + fr_FR
Hungarian hu + +
Indonesian id + +
Italian it + -
Kurdish ku + -
Lithuanian lt + +
Latvian lv + +
Macedonian mk + -
Malay ms + +
Persian fa + -
Polish pl + +
Portuguese pt_PT + +
Romanian ro + +
Serbian sr + +
Slovak sk + +
Spanish es + +
Russian ru + +
Swahili sw + +
Swedish sv + -
Turkish tr + +
Turkmen tk + +
Ukrainian ua + +
Uzbek uz + +
Yoruba yo + +

Contributors

Some transformers were ported from the pear/Numbers_Words library. Others were created by contributors. Thank you!

Version 3.x - BC and major changes

  • Dropped support for PHP <8.2.
  • Changed Romanian currency code from ROL to RON

Version 2.x - BC and major changes

  • Dropped support for PHP <7.4.
  • Added typehints for NumberTransformer and CurrencyTransformer interfaces. Now both accept integer numbers only (Albanian language might be affected).
  • Added support for PSR12.

Questions and answers

Q: What should I do if I encounter a bug while using the library?

A: If you come across a bug, please open an issue on our GitHub repository. As I may not be proficient in all languages, we encourage users to submit fixes and collaborate to enhance the library's functionality.

Q: My language is missing. Could it be added?

A: There's a high chance I don't know your language. Feel free to implement the missing language and open a pull request. You can use the existing languages as a reference.

kwn/number-to-words 适用场景与选型建议

kwn/number-to-words 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.45M 次下载、GitHub Stars 达 426, 最近一次更新时间为 2015 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「money」 「currency」 「numbers」 「number」 「string」 「words」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kwn/number-to-words 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kwn/number-to-words 我们能提供哪些服务?
定制开发 / 二次开发

基于 kwn/number-to-words 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.45M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 437
  • 点击次数: 32
  • 依赖项目数: 28
  • 推荐数: 1

GitHub 信息

  • Stars: 426
  • Watchers: 14
  • Forks: 167
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-08