Giter Site home page Giter Site logo

sohag1426 / forked-spellnumber Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rmunate/spellnumber

0.0 0.0 0.0 47 KB

Easily convert numbers to words in Laravel using this library, which supports the native PHP INTL extension to perform the conversion seamlessly. This library allows you to convert numbers to words in multiple languages and also get the value in currency format based on the selected language.

Home Page: https://laravel-news.com/spellnumber-words-to-numbers-in-laravel

PHP 100.00%

forked-spellnumber's Introduction

Convert Numbers to Words in Laravel

Easily convert numbers to words in Laravel using this library, which leverages the native PHP INTL extension to perform conversion effortlessly. With this library, you can convert numbers to words in various languages and also obtain the value in currency format according to the selected language. Supported languages include English, Spanish, Portuguese, French, Italian, Romanian, and with the contribution of Siros Fakhri, Persian (Farsi) support has been added.

⚙️ This library is compatible with Laravel versions 8.0 and higher ⚙️

Laravel 8.0+ Laravel 9.0+ Laravel 10.0+

SpellNumbers

Table of Contents

Installation

To install the dependency via Composer, execute the following command:

composer require rmunate/spell-number

It's important to ensure that the intl extension is enabled and loaded in the environment.

Usage

After installing the dependency in your project, you can start using it with the following examples:

Knowing Supported Regional Configurations

To obtain the current list of languages with support, execute the following command:

SpellNumber::getAllLocales();
// array:7 [▼
//     0 => "en" (English)
//     1 => "es" (Spanish)
//     2 => "pt" (Portuguese)
//     3 => "fr" (French)
//     4 => "it" (Italian)
//     5 => "ro" (Romanian)
//     6 => "fa" (Farsi)
// ]

Convert Integers to Words

You can easily convert numbers to words by defining the regional configuration to apply. If you don't define a regional configuration, "en" (English) will be applied by default.

SpellNumber::value(100)->locale('es')->toLetters();
// "Cien"

SpellNumber::value(100)->locale('fa')->toLetters();
// "صد"

SpellNumber::value(100)->locale('en')->toLetters();
// "One Hundred"

Convert Floating-Point Numbers

If needed, you can pass a floating-point number as an argument to convert it to words.

SpellNumber::value(123456789.12)->locale('es')->toLetters();
// "Ciento Veintitrés Millones Cuatrocientos Cincuenta Y Seis Mil Setecientos Ochenta Y Nueve Con Doce"

Convert to Currency Format

This method can be useful for invoices, receipts, and similar scenarios. Obtain the supplied value in currency format.

SpellNumber::value(100)->locale('es')->currency('pesos')->toMoney();
// "Cien Pesos"

SpellNumber::value(100.12)->locale('es')->currency('Pesos')->fraction('centavos')->toMoney();
// "Cien Pesos Con Doce Centavos"

SpellNumber::value(100)->locale('fa')->currency('تومان')->toMoney();
// "صد تومان"

Other Initializer Methods

To support version 1.X, the following initializer methods are maintained.

// Integer, this method strictly requires an integer value to be sent as an argument.
SpellNumber::integer(100)->locale('es')->toLetters();

// Floating-point numbers, this method strictly requires a string value as an argument.
SpellNumber::float('12345.23')->locale('es')->toLetters();

Creator

Contributors

Siros Fakhri (Farsi Language)

License

This project is licensed under the MIT License.

forked-spellnumber's People

Contributors

rmunate avatar stylecibot avatar sirosfakhri 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.