lubosdz/number-to-words 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

lubosdz/number-to-words

最新稳定版本:1.0.6

Composer 安装命令:

composer require lubosdz/number-to-words

包简介

Number to words conversion - locale specific.

README 文档

README

PHP utility for converting arbitrary float or integer number to words, mainly in English, Slovak and Czech. These have custom PHP implementation, which will fix INTL/ICU bugs and allows for output customization. Other languages are supported too, but only using INTL/ICU PHP extension, which might be buggy.

Installation

  • via composer:
$ composer require "lubosdz/number-to-words" : "~1.0.0"

Demo & repo

Usage

// use either factory ..
use lubosdz\numberToWords\NumberToWords;

// .. or language specific implementation
use lubosdz\numberToWords\NumberToWords_SK;
use lubosdz\numberToWords\NumberToWords_CZ;
use lubosdz\numberToWords\NumberToWords_EN;

// Slovensky / Slovak
NumberToWords::convert(123.45, 'sk'); // jednostodvadsaťtri celé štyridsaťpäť
NumberToWords_SK::convert(123.45); // jednostodvadsaťtri celé štyridsaťpäť
NumberToWords_SK::convertIntl(123.45); // jedna­sto dvasať­tri čiarka štyri päť (ICU returns "dvasať", bug)

// supply number as string - will retain right-sided zeroes on decimal part
NumberToWords_SK::convert(37.40); // tridsaťsedem celé štyri - strip off right-sided zeroes
NumberToWords_SK::convert("37.40"); // tridsaťsedem celé štyridsať - keep right-sided zeroes
NumberToWords_SK::convert("37.400"); // tridsaťsedem celé štyristo - keep right-sided zeroes

// arbitrary decimals word separator
NumberToWords_EN::$txtDecimal = " čiarka ";
NumberToWords_EN::convert(12.30); // dvanásť čiarka tridsať

// with decimals as a fraction - useful in accounting
NumberToWords::$decimalsAsFraction = true;
NumberToWords::convert(123.45, 'sk'); // jednostodvadsaťtri (45/100)

// enforce desired number of decimals
NumberToWords::$numberOfdecimals = 2;
NumberToWords::convert(12.3, 'sk'); // dvanásť celé tridsať

// Česky / Czech:
NumberToWords::convert(123.45, 'cz'); // allowed cz or cs, // sto dvacet tři celá čtyřicet pět
NumberToWords_CZ::convert(123.45); // sto dvacet tři celá čtyřicet pět
NumberToWords_CZ::convertIntl(123.45); // sto dvacet tři celá čtyři pět

// English:
NumberToWords::convert(123.45); // lang code not needed since english is default
NumberToWords_EN::convert(123.45); // one hundred twenty-three point fourty-five
NumberToWords_EN::convertIntl(123.45); // one hundred twenty-three point four five

// arbitrary decimals word separator
NumberToWords_EN::$txtDecimal = " comma ";
NumberToWords_EN::convert(12.30); // twelve comma thirty

// really big number:
NumberToWords_EN::convert(987654321.123);
// nine hundred eighty-seven million, six hundred fifty-four thousand, three hundred twenty-one point one hundred twenty-three

NumberToWords_EN::convertIntl(987654321.123);
// nine hundred eighty-seven million six hundred fifty-four thousand three hundred twenty-one point one two three

// Russian:
NumberToWords::convert(123.45, 'ru'); // сто двадцать три целых сорок пять сотых

// German:
NumberToWords::convert(123.45, 'de'); // ein­hundert­drei­und­zwanzig Komma vier fünf

// French:
NumberToWords::convert(123.45, 'fr'); // cent vingt-trois virgule quatre cinq

Changelog

1.0.6 - 15.08.2024

  • support enforcing the number of decimals

1.0.5 - 10.08.2024

  • make decimals separator word configurable
  • clearify documentation on how to keep right-padded zeroes on decimal part
  • added tests

1.0.4 - 04.02.2024

  • Support decimals as a fraction
  • Fixed zeroes in decimal part on left side
  • added unit tests

1.0.3 - 02.07.2023

  • Fixed PHP 8.2 compatability

1.0.2 - 12.03.2021

  • extended support for any language via INTL/ICU extension

1.0.1 - 12.03.2021

  • added factory class NumberToWords::convert($num, $lang)

1.0.0 - 22.05.2020

  • initial release (SK, EN, CZ)

统计信息

  • 总下载量: 2.32k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-05-22