Giter Club home page Giter Club logo

number-to-words's Introduction

Number to words

Issues Stars

Installation and setup

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' => [
            'रुपैया', 'पैसा'
        ]
    ],


];

Optional Paramater ( Array - available keys and values)

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

Basic Usage

echo NumberToWords::get(123456789);

//output : Twelve Crore Thirty-four Lakh Fifty-six Thousand Seven Hundred Eighty-nine Rupees and Twelve Paisa

Usage with config as optional paramater

Example 1

$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
 

Example 2

$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"
]

number-to-words's People

Contributors

milantarami avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.