PHP code example of pinoox / numera

1. Go to this page and download the library: Download pinoox/numera library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pinoox / numera example snippets


use Pino\Numera;

echo Numera::init('en')->n2w(1234);
echo Numera::init('fa')->n2w('۱۲۳۴');
echo Numera::init('en')->toYear(2024);

'default_locale' => 'en',   // or fa, de, fa-IR, …
'fallback_locale' => 'en',

use Pinoox\Numera\Laravel\Facades\Numera;

echo Numera::n2w(1234);
echo Numera::toYear(2024);
echo Numera::setLocale('fa')->n2w(-500);

use Pino\Numera;

$numera = Numera::init('en'); // Initialize with English locale

$result = $numera->convertToWords(4454545156);
echo $result; // Output: "four billion, four hundred fifty-four million, five hundred forty-five thousand, one hundred fifty-six"

$result = $numera->n2w('4,454,545,156');
echo $result; // Output: "four billion, four hundred fifty-four million, five hundred forty-five thousand, one hundred fifty-six"

echo Numera::init('en')->n2w(-500);  // negative five hundred
echo Numera::init('fa')->n2w(-500);  // منفی پانصد

echo Numera::init('en')->n2w(3.14);       // three point one four
echo Numera::init('en')->n2w('1,250.75'); // one thousand, two hundred fifty point seven five
echo Numera::init('fa')->n2w(3.14);       // سه ممیز یک چهار

$numera = Numera::init('en');
echo $numera->toOrdinal(21);  // twenty-first
echo $numera->n2o(100);       // one hundredth

$numera->setLocale('fa');
echo $numera->toOrdinal(3);   // سوم
echo $numera->toOrdinal(21);  // بیست و یکم

echo Numera::init('en')->toCurrency(1250.50, 'USD');
// one thousand, two hundred fifty dollars and fifty cents

echo Numera::init('fa')->toCurrency(150000, 'IRR');
// صد و پنجاه هزار ریال

echo Numera::init('en')->toCurrency(3.01, 'GBP');
// three pounds and one penny

echo Numera::init('en')->withUnit(1, 'kg');   // one kilogram
echo Numera::init('en')->withUnit(5, 'hour'); // five hours
echo Numera::init('fa')->withUnit(1, 'day');  // یک روز

echo Numera::init('en')->toWeekday(1);        // monday
echo Numera::init('en')->toWeekday('friday'); // friday
echo Numera::init('fa')->toWeekday(5);        // جمعه (ISO: Friday)
echo Numera::init('fa')->toWeekday(6);        // شنبه (ISO: Saturday)
echo Numera::init('fa')->d2w('saturday');     // شنبه

// All days; Persian locale starts on Saturday (meta.week_starts_on)
print_r(Numera::init('fa')->getWeekdays());

// Persian → English
echo Numera::init('fa')->translateTo('en', 'دویست و یک');  // two hundred one
echo Numera::init('fa')->translateTo('en', 'شنبه');       // saturday

// English → Persian
echo Numera::init('en')->translateTo('fa', 'two hundred one'); // دویست و یک
echo Numera::init('en')->t2t('monday', 'fa');                 // دوشنبه

LocaleTranslator::between('fa', 'en')->translate('منفی پانصد'); // negative five hundred

echo Numera::init('en')->setCamelCase(true)->n2w(-10); // Negative Ten

$result = $numera->convertToSummary(4454545156);
echo $result; // Output: "4 Billion, 454 Million, 545 Thousand, 156"

$result = $numera->n2s('4,454,545,156');
echo $result; // Output: "4 Billion, 454 Million, 545 Thousand, 156"

$result = $numera->convertToNumber('four billion, four hundred fifty-four million, five hundred forty-five thousand, one hundred fifty-six');
echo $result; // Output: 4454545156

$result = $numera->w2n("4 Billion, 454 Million, 545 Thousand, 156");
echo $result; // Output: 4454545156

$result = $numera->w2n('four billion, four hundred fifty-four million, five hundred forty-five thousand, one hundred fifty-six', [' ', ',']);
echo $result; // Output: 4454545156

$numera->setCamelCase(true);
$result = $numera->convertToWords('4,454,545,156');
echo $result; // Output: "Four Billion, Four Hundred Fifty-Four Million, Five Hundred Forty-Five Thousand, One Hundred Fifty-Six"

Numera::detectFormat("1.234.567,89"); // european
echo Numera::init('en')->n2w('۱۲۳۴');
echo Numera::init('en')->n2w("1'234'567.89");
echo Numera::init('en')->n2w('1_000_000');

echo Numera::init('en')->toFraction(0.5);   // one half
echo Numera::init('en')->n2f(1.5);         // one and a half
echo Numera::init('fa')->toFraction(0.5);  // نیم

echo Numera::init('en')->toYear(2024);  // twenty twenty-four
echo Numera::init('en')->n2y(2000);     // two thousand
echo Numera::init('fa')->toYear(1402);  // cardinal Persian form

echo Numera::init('en')->toPhone('+1 415 555 0172');
echo Numera::init('en')->n2p('021-8834-1100');

echo Numera::init('en')->toRoman(1999);      // MCMXCIX
echo Numera::fromRoman('xiv');               // 14

echo Numera::init('en')->toIp('192.168.1.1');
echo Numera::init('en')->n2ip('10.0.0.1');
echo Numera::init('en')->toVersion('2.14.0');
echo Numera::init('en')->toVersion('1.0.0-beta');

Numera::init('en-US')->n2w(42);       // same words as en, US meta
Numera::init('en-GB')->toCurrency(3.01, 'GBP');
Numera::init('fa-IR')->getWeekdays();  // inherits fa (week starts Saturday)
Numera::init('de-AT')->getStrategyName(); // german (inherited from de)

$numera->setLocale('fa'); // Set locale to Persian

$numera->setLocaleFallback('en'); // Set fallback locale to English

$translates = $numera->getTranslates();
print_r($translates); // Output: Array of translates for the current locale

$numera->addTranslate('fr', ['four' => 'quatre']); // Add French translates

$numera->addTranslateFile('fr','/path/lang/fr.php'); // Add French translates

src/
  Numera.php              # Main API
  LocaleRegistry.php      # Locale load/merge (regional variants)
  Strategy/               # german, french, multiplier_tens, default
  Support/                # Input parsers, fractions, phone, IP, …
  Languages/              # English-specific year rules
  lang/                   # Per-locale translations (184+ files)
  data/                   # numbers.php, regional-locales, …
tests/                    # PHPUnit (1000+ tests)
bash
php artisan vendor:publish --tag=numera-config