You can install this package via composer using:
composer require milantarami/number-to-words
The package will automatically register its service provider for laravel 5.5.* and above.
For below version need to register a service provider manually in config/app.php
'providers' => [
/*
* Package Service Providers...
*/
MilanTarami\NumberToWordsConverter\NumberToWordsServiceProvider::class
],
The package will automatically load alias for laravel 5.5.* and above.
For below version need to add alias manually in config/app.php
'aliases' => [
.
.
'NumberToWords' => MilanTarami\NumberToWordsConverter\Facades\NumberToWordsFacade::class,
]
To publish the config file to config/number_to_words.php
run:
php artisan vendor:publish --tag=number-to-words-config
This is the default contents of the configuration:
<?php
return [
/**
* Add a monetary unit notation to response
* [ true / false ]
* default = true
**/
'monetary_unit_enable' => true,
/**
* supported response language
* [ English (en) / Nepali [np] ]
* default = en
**/
'lang' => 'en',
/**
* supported Response Type
* [ 'string', 'array' ]
* default = string
**/
'response_type' => 'string',
/**
* supported numbering systems
* [ Nepali Numbering System (nns) / International Numbering System (ins) ]
* default = nns
**/
'numbering_system' => 'nns',
/**
* Monetary Units for Nepal [ in English and Nepali ]
* ex [ 'Dollar', 'Cent ]
**/
'monetary_unit' => [
'en' => [
'Rupees', 'Paisa'
],
'np' => [
'रुपैया', 'पैसा'
]
],
];
Key | Description | Type | Avaliable Values | Default |
---|---|---|---|---|
monetary_unit_enable | Enable / Disable monetary unit in response | Boolean | true, false | true |
lang | Nepali and English Languages are avaliable | String | en, np | en |
response_type | Output can be returned in String and Array Format | String | string, array | string |
numbering_system | Two Numbering System are avaliable are Nepali Numbering System (nns) and International Numbering System (ins) | String | nns, ins | nns |
monetary_unit | You can setup your custom monetary unit in output by replacing Rupees / Paisa as Dollar / Cent . | Array | Use custom value as array [ 'Dollar', 'Cent' ] | Depends upon language selected |
echo NumberToWords::get(123456789);
//output : Twelve Crore Thirty-four Lakh Fifty-six Thousand Seven Hundred Eighty-nine Rupees and Twelve Paisa
$config = [
'monetary_unit' => [ 'Dollar', 'Cent' ],
'numbering_system' => 'ins'
];
echo NumberToWords::get(123456789.12, $config);
//output : One Hundred Twenty-three Million Four Hundred Fifty-six Thousand Seven Hundred Eighty-nine Dollar and Twelve Cent
$config = [
'monetary_unit' => [ 'Dollar', 'Cent' ],
'numbering_system' => 'ins',
'response_type' => 'array'
];
dd(NumberToWords::get(123456789.12, $config));
//output :
array:7 [▼
"integer" => 123456789
"integer_in_words" => "One Hundred Twenty-three Million Four Hundred Fifty-six Thousand Seven Hundred Eighty-nine Dollar"
"point" => 12
"point_in_words" => "Twelve Cent"
"original_input" => "123456789.12"
"formatted_input" => "123,456,789.12"
"in_words" => "One Hundred Twenty-three Million Four Hundred Fifty-six Thousand Seven Hundred Eighty-nine Dollar and Twelve Cent"
]