rundiz/number

Number conversion (number to text) (Thai and English)

1.1.8 2021-12-08 08:55 UTC

This package is auto-updated.

Last update: 2024-10-10 20:19:09 UTC


README

The Number classes provide formatting, convertions classes and methods for working with numeric values.
The Number[Language] class is for convert number to text in Thai and English languages.
In Thai language it is including number to Thai Baht conversion.

Latest Stable Version License Total Downloads

Example:

Convert number:

// For English require NumberEng.php, for Thai require NumberThai.php
require 'Rundiz/Number/NumberEng.php';

// For English use NumberEng(), for Thai use NumberThai()
$number_text = new Rundiz\Number\NumberEng();

echo $number_text->convertNumber('101');
// the result should be:
// one hundred and one (for English)
// หนึ่งร้อยเอ็ด (for Thai)

Convert Thai Baht:

require 'Rundiz/Number/NumberThai.php';

$number_text = new Rundiz\Number\NumberThai();

echo $number_text->convertBaht('3.23');
// the result should be:
// สามบาทยี่สิบสามสตางค์

Convert file size to Bytes:

require 'Rundiz/Number/Number.php';

$number = new Rundiz\Number\Number();

echo $number->toBytes('1.3KB'); // 1300
echo $number->toBytes('1.3KiB'); // 1331.2

Convert to other file size unit from Bytes:

require 'Rundiz/Number/Number.php';

$number = new Rundiz\Number\Number();

echo $number->fromBytes('100000'); // 100.00 KB
echo $number->fromBytes('133300'); // 133.30 KB
echo $number->fromBytes('10000', 'KiB); // 9.76 KiB

Remove dot zero digits:

require 'Rundiz/Number/Number.php';

$Number = new Rundiz\Number\Number();

echo $Number->removeDotZero('1987.0000000000'); // 1987
echo $Number->removeDotZero('35.400'); // 35.400
echo $Number->removeDotZero('35.400', false); // 35.4
echo $Number->removeDotZero('35,400', false, ','); // 35,4 (european number format)

For more example, please look inside tests folder.