Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Number to Words in Indian currency format with paise value [duplicate]

Using PHP how to convert number to Indian currency word format with paise (decimal value)

Input
190908100.25

Output we need

nineteen crores nine lakh eight thousand one hundred Rupees .two five Paise

I expect this conversion method in core php .

like image 994
Sakthi Karthik Avatar asked Sep 22 '14 06:09

Sakthi Karthik


People also ask

How do you convert currency into words?

Use the SpellNumber function in individual cells Type the formula =SpellNumber(A1) into the cell where you want to display a written number, where A1 is the cell containing the number you want to convert. You can also manually type the value like =SpellNumber(22.50). Press Enter to confirm the formula.

What is the difference between Indian and international number format?

While in Indian format we use Lakh, Crore, Arab etc. and separates placed after every two digits. 2. Number in English Words (Indian format) - You can read number in English words in Indian number format that have lakh and crores instead of million and billion of international number format.

How to convert number to words?

Just enter the amount and click on "Convert in Words" button you will get your number are converted in words. You can copy resultant words and use it anywhere you want. It's a free but powerful number to word converter that gives output in Indian Rupees format also, useful for complete your task and save lots of time.

How to convert numbers to words in rupees in Excel?

The following VBA code can help you to convert the numbers to words in rupees, please do as this: 1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window. 2. Click Insert > Module, and paste the following code in the Module Window.

How to read number in English words (Indian format)?

Number in English Words (Indian format) - You can read number in English words in Indian number format that have lakh and crores instead of million and billion of international number format. Here you change case of words in various format like - Sentence case, Title Case, Capital case, Lower case and Upper case.


1 Answers

Convert Currency Number to Word Format Using PHP

 <?php
  /**
   * Created by PhpStorm.
   * User: sakthikarthi
   * Date: 9/22/14
   * Time: 11:26 AM
   * Converting Currency Numbers to words currency format
   */
$number = 190908100.25;
   $no = floor($number);
   $point = round($number - $no, 2) * 100;
   $hundred = null;
   $digits_1 = strlen($no);
   $i = 0;
   $str = array();
   $words = array('0' => '', '1' => 'one', '2' => 'two',
    '3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six',
    '7' => 'seven', '8' => 'eight', '9' => 'nine',
    '10' => 'ten', '11' => 'eleven', '12' => 'twelve',
    '13' => 'thirteen', '14' => 'fourteen',
    '15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
    '18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',
    '30' => 'thirty', '40' => 'forty', '50' => 'fifty',
    '60' => 'sixty', '70' => 'seventy',
    '80' => 'eighty', '90' => 'ninety');
   $digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
   while ($i < $digits_1) {
     $divider = ($i == 2) ? 10 : 100;
     $number = floor($no % $divider);
     $no = floor($no / $divider);
     $i += ($divider == 10) ? 1 : 2;
     if ($number) {
        $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
        $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
        $str [] = ($number < 21) ? $words[$number] .
            " " . $digits[$counter] . $plural . " " . $hundred
            :
            $words[floor($number / 10) * 10]
            . " " . $words[$number % 10] . " "
            . $digits[$counter] . $plural . " " . $hundred;
     } else $str[] = null;
  }
  $str = array_reverse($str);
  $result = implode('', $str);
  $points = ($point) ?
    "." . $words[$point / 10] . " " . 
          $words[$point = $point % 10] : '';
  echo $result . "Rupees  " . $points . " Paise";
 ?> 
  • Output

    nineteen crores nine lakh eight thousand one hundred Rupees . two five Paise


    Now i have added Simplified Method as follows:
    
    

    function getIndianCurrency(float $number) { $decimal = round($number - ($no = floor($number)), 2) * 100; $hundred = null; $digits_length = strlen($no); $i = 0; $str = array(); $words = array(0 => '', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', 19 => 'nineteen', 20 => 'twenty', 30 => 'thirty', 40 => 'forty', 50 => 'fifty', 60 => 'sixty', 70 => 'seventy', 80 => 'eighty', 90 => 'ninety'); $digits = array('', 'hundred','thousand','lakh', 'crore'); while( $i < $digits_length ) { $divider = ($i == 2) ? 10 : 100; $number = floor($no % $divider); $no = floor($no / $divider); $i += $divider == 10 ? 1 : 2; if ($number) { $plural = (($counter = count($str)) && $number > 9) ? 's' : null; $hundred = ($counter == 1 && $str[0]) ? ' and ' : null; $str [] = ($number < 21) ? $words[$number].' '. $digits[$counter]. $plural.' '.$hundred:$words[floor($number / 10) * 10].' '.$words[$number % 10]. ' '.$digits[$counter].$plural.' '.$hundred; } else $str[] = null; } $Rupees = implode('', array_reverse($str)); $paise = ($decimal > 0) ? "." . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' Paise' : ''; return ($Rupees ? $Rupees . 'Rupees ' : '') . $paise; }

method calling :

echo getIndianCurrency(79855995.19);

output seven crore ninety eight lakhs fifty five thousands nine hundred and ninety five Rupees .one nine Paise

like image 191
Sakthi Karthik Avatar answered Oct 13 '22 10:10

Sakthi Karthik