All Projects → kwn → Number To Words

kwn / Number To Words

Licence: mit
Number to string standalone PHP library with i18n. Drivers for numbers and currency included.

Projects that are alternatives of or similar to Number To Words

DataTypes
Built-in data types
Stars: ✭ 34 (-85.47%)
Mutual labels:  string, number
prototyped.js
Some common Typescript prototypes
Stars: ✭ 22 (-90.6%)
Mutual labels:  string, number
is-primitive
Is the typeof value a javascript primitive?
Stars: ✭ 35 (-85.04%)
Mutual labels:  string, number
rxjs-ninja
RxJS Operators for handling Observable strings, numbers, booleans and more
Stars: ✭ 68 (-70.94%)
Mutual labels:  string, number
DigitText
The module allows to translate numbers into a text equivalent. This is important in the billing.
Stars: ✭ 22 (-90.6%)
Mutual labels:  string, number
Ssf
📝 Spreadsheet Number Formatter
Stars: ✭ 139 (-40.6%)
Mutual labels:  string, number
Libphonenumber Js
A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
Stars: ✭ 2,233 (+854.27%)
Mutual labels:  number
Util
A collection of useful utility functions
Stars: ✭ 201 (-14.1%)
Mutual labels:  string
Algo Tree
Algo-Tree is a collection of Algorithms and data structures which are fundamentals to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. It contains solutions in various languages such as C++, Python and Java.
Stars: ✭ 166 (-29.06%)
Mutual labels:  string
Androidlibrary
Android library to reveal or obfuscate strings and assets at runtime
Stars: ✭ 162 (-30.77%)
Mutual labels:  string
Superstring.py
A fast and memory-optimized string library for heavy-text manipulation in Python
Stars: ✭ 231 (-1.28%)
Mutual labels:  string
Codejam
Set of handy reusable .NET components that can simplify your daily work and save your time when you copy and paste your favorite helper methods and classes from one project to another
Stars: ✭ 217 (-7.26%)
Mutual labels:  string
React Flip Numbers
🎰 Flip your numbers in 3D
Stars: ✭ 185 (-20.94%)
Mutual labels:  number
Is Number
JavaScript/Node.js utility. Returns `true` if the value is a number or string number. Useful for checking regex match results, user input, parsed strings, etc.
Stars: ✭ 176 (-24.79%)
Mutual labels:  number
Actual Number Picker
Android: A horizontal number picker
Stars: ✭ 206 (-11.97%)
Mutual labels:  number
Strman
🏗A Javascript string manipulation library.
Stars: ✭ 2,021 (+763.68%)
Mutual labels:  string
Php To String
Cast any php value into a string
Stars: ✭ 219 (-6.41%)
Mutual labels:  string
Voca rs
Voca_rs is the ultimate Rust string library inspired by Voca.js, string.py and Inflector, implemented as independent functions and on Foreign Types (String and str).
Stars: ✭ 167 (-28.63%)
Mutual labels:  string
Swiftyfitsize
📱 Swifty screen adaptation solution (Support Objective-C and Swift)
Stars: ✭ 184 (-21.37%)
Mutual labels:  number
Blitz
Android Library: Set self-updating string with relative time in TextView (e.g. 5 minutes ago)
Stars: ✭ 217 (-7.26%)
Mutual labels:  string

PHP Number to words converter

Travis Code Climate Test Coverage Latest Stable Version

This library allows you to convert a number to words.

Installation

Add package to your composer.json by running:

$ composer require kwn/number-to-words

Usage

This library currently has two types of number-to-words transformations: number and currency. In order to use a specific transformer for certain language you need to create an instance of NumberToWords class and then call a method which creates a new instance of a transformer;

Number Transformer

Before using a transformer, it must be created:

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');

Then it can be used passing in numeric values to the toWords() method:

$numberTransformer->toWords(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"

Bare in mind, the currency transformer accepts integers as the amount to transform. It means that if you store amounts as floats (e.g. 4.99) you need to multiply them by 100 and pass the integer (499) as an argument.

Available locale

Language Identifier Number Currency
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 + +
Hungarian hu + +
Indonesian id + -
Italian it + -
Lithuanian lt + +
Latvian lv + +
Malay ms + -
Persian fa + -
Polish pl + +
Romanian ro + +
Slovak sk + -
Spanish es + +
Russian ru + +
Swedish sv + -
Turkish tr + +
Turkmen tk + +
Ukrainian ua + +
Yoruba yo + +

Contributors

Most of the transformers were ported from pear/Numbers_Words library. Some of them were slightly refactored. Some of them were created by other contributors who were helping me with the initial version of that library.

This library is still under a heavy refactoring so the legacy code should ultimately disappear.

Questions and answers

Q: Why the code looks like a crap? Why it gets so low rank on code climate?

A: Most of the code was just migrated from pear/Numbers_Words. That library still remembers the ages of PHP4. I constantly refactor it, so it's getting better. I'm also porting some mechanisms from other languages so sooner or later it will look quite good.

Q: There's an error!

A: Please report an issue, or even better - create a pull request. I don't speak most of those languages so your help is much appreciated. Thanks!

Q: Why there are some transformers which cannot be used (they live under UntestedLocale namespace)?

A: Simply, because there are no test cases for them. You're more than welcome to create some test cases for them, so we'll be able to include them in a list of available languages.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].