convert number to words in codeigniter

Today, We want to share with you convert number to words in codeigniter.In this post we will show you indian currency number to words, hear for Number::spell() – spell numbers as words, In Javascript isnan function. we will give you demo and example for implement.In this post, we will learn about php spell out number with an example.

There are the following the learn about convert number to words in codeigniter.

  • Convert Number To Words In Codeigniter
  • Convert Number To Words In Javascript
  • uses this javascript library

convert number to words in codeigniter

There are the Following The simple About convert date of birth in words in php Full Information With Example and source code.

As I will cover this Post with live Working example to develop convert number to words in indian rupees in codeigniter, so the convert number to words in indian rupees in laravel is used for this example is following below.

convert number to words in html,convert decimal number to words in javascript,convert date in words in php,convert date of birth in words in php,how to convert number to words in indian rupees,convert number into words indian currency,convert number to words in indian rupees in laravel,php code to convert rupees into words,convert number to words in indian rupees in asp net,convert number to words in jquery,php date in words,convert number to letter in php,
convert number to words in codeigniter

convert number to words in codeigniter

Create library Name with convertNumbersIntoWords.php

convertNumbersIntoWords.php

<?php
if (!defined('BASEPATH'))
  exit('No direct script access allowed');
class convertNumbersIntoWords {
    function convert_number($figure) {
        if (($figure < 0) || ($figure > 999999999)) {
            throw new Exception("Your Number is out of range");
        }
        $giga = floor($figure / 1000000);
        // Millions (giga)
        $figure -= $giga * 1000000;
        $kilo = floor($figure / 1000);
        // Thousands (kilo)
        $figure -= $kilo * 1000;
        $hecto = floor($figure / 100);
        // Hundreds (hecto)
        $figure -= $hecto * 100;
        $deca = floor($figure / 10);
        // Tens (deca)
        $n = $figure % 10;
        // Ones
        $result = "";
        if ($giga) {
            $result .= $this->convert_number($giga) .  "Million";
        }
        if ($kilo) {
            $result .= (empty($result) ? "" : " ") .$this->convert_number($kilo) . " Thousand";
        }
        if ($hecto) {
            $result .= (empty($result) ? "" : " ") .$this->convert_number($hecto) . " Hundred";
        }
        $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen", "Nineteen");
        $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eigthy", "Ninety");
        if ($deca || $n) {
            if (!empty($result)) {
                $result .= " and ";
            }
            if ($deca < 2) {
                $result .= $ones[$deca * 10 + $n];
            } else {
                $result .= $tens[$deca];
                if ($n) {
                    $result .= "-" . $ones[$n];
                }
            }
        }
        if (empty($result)) {
            $result = "zero";
        }
        return $result;
    }
}
?>

This library can be used in your CodeIgniter project. And the usage is very simple. Just import the library and call the function as follows:

Read Also:  php application global config and settings - php superglobals

usage library

<?php
$val = $this->load->library('convertNumbersIntoWords');
$figure = 1234567890;
echo $this->convertNumbersIntoWords->convert_number($figure);
?>

convert Number to words in javascript

File Create File Name with convertNumbersIntoWords.js

convertNumbersIntoWords.js

// System for American Numbering 
var th_val = ['', 'thousand', 'million', 'billion', 'trillion'];
// System for uncomment this line for Number of English 
// var th_val = ['','thousand','million', 'milliard','billion'];
 
var dg_val = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
var tinfinity_value = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];
var tw_val = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
function toWordsconver(s) {
  s = s.toString();
    s = s.replace(/[\, ]/g, '');
    if (s != parseFloat(s))
        return 'not a number ';
    var x_number_data = s.indexOf('.');
    if (x_number_data == -1)
        x_number_data = s.length;
    if (x_number_data > 15)
        return 'too big';
    var infinity_value = s.split('');
    var txt_data = '';
    var sk_val = 0;
    for (var i = 0; i < x_number_data; i++) {
        if ((x_number_data - i) % 3 == 2) {
            if (infinity_value[i] == '1') {
                txt_data += tinfinity_value[Number(infinity_value[i + 1])] + ' ';
                i++;
                sk_val = 1;
            } else if (infinity_value[i] != 0) {
                txt_data += tw_val[infinity_value[i] - 2] + ' ';
                sk_val = 1;
            }
        } else if (infinity_value[i] != 0) {
            txt_data += dg_val[infinity_value[i]] + ' ';
            if ((x_number_data - i) % 3 == 0)
                txt_data += 'hundred ';
            sk_val = 1;
        }
        if ((x_number_data - i) % 3 == 1) {
            if (sk_val)
                txt_data += th_val[(x_number_data - i - 1) / 3] + ' ';
            sk_val = 0;
        }
    }
    if (x_number_data != s.length) {
        var y_val = s.length;
        txt_data += 'point ';
        for (var i = x_number_data + 1; i < y_val; i++)
            txt_data += dg_val[infinity_value[i]] + ' ';
    }
    return txt_data.replace(/\s+/g, ' ');
}

uses this javascript library

// convertNumbersIntoWords.js for Import the javascript file:
 
<script type="text/javascript" src="convertNumbersIntoWords.js"></script>
// Call the function toWordsconver(number) passing a number to it: 
<script>  
    var figure = 9841;  
    var Inwords = toWordsconver(figure);
</script>

Web Programming Tutorials Example with Demo

Read :

Read Also:  PHP Sorting Multidimensional Array By Key

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Spell out numbers with PHP codeigniter to transform numeric values into strings.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.