php - Convert Number to Words in Indian currency format with paise value -


this question has answer here:

using php how convert number indian currency word format paise (decimal value)

input
190908100.25

output need

nineteen crores 9 lakh 8 thousand 1 hundred rupees .two 5 paise 

i need conversion method in php.

convert currency number word format using php

 <?php   /**    * created phpstorm.    * user: sakthikarthi    * date: 9/22/14    * time: 11:26    * converting currency numbers words currency format    */ $number = 190908100.25;    $no = round($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]) ? ' , ' : 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 9 lakh 8 thousand 1 hundred rupees . 2 5 paise


    now have added simplified method 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]) ? ' , ' : 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) ? "." . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' paise' : ''; return ($rupees ? $rupees . 'rupees ' : '') . $paise .; }

method calling :

echo getindiancurrency(79855995.19);

output seven crore ninety 8 lakhs fifty 5 thousands 9 hundred , ninety 5 rupees .one 9 paise


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -