13

使用 PHP 如何将数字转换为带有 paise 的印度货币字格式(十进制值)

输入
190908100.25

我们需要的输出

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

我希望在 core 中使用这种转换方法php

4

1 回答 1

85

将货币数字转换为 Word 格式使用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";
 ?> 
  • 输出

    1.9 亿 90 万 8100 卢比。二五派塞


    现在我添加了简化方法如下:

    函数 getIndianCurrency(float $number) { $decimal = round($number - ($no = floor($number)), 2) * 100; $百=空; $digits_length = strlen($no); $i = 0; $str = 数组(); $words = array(0 => '', 1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六', 7 => '七', 8 => '八', 9 => '九', 10 => '十', 11 => '十一', 12 => '十二', 13 => '十三', 14 => '十四', 15 => '十五', 16 => '十六', 17 => '十七', 18 => '十八', 19 => '十九', 20 => '二十', 30 => '三十', 40 => '四十', 50 => '五十', 60 => '六十', 70 => '七十', 80 => '八十', 90 => '九十'); $digits = array('', 'hundred','thousand','lakh', 'crore'); 而($i < $digits_length){ $分频器 = ($i == 2) ? 10:100; $number = floor($no % $divider); $no = floor($no / $divider); $i += $分频器 == 10 ?1:2; 如果($数字){ $plural = (($counter = count($str)) && $number > 9) ? 's':空; $hundred = ($counter == 1 && $str[0]) ?' 和 ' : null; $str [] = ($number < 21) ? $words[$number]。'。$数字[$计数器]。$复数。'.$hundred:$words[floor($number / 10) * 10].' '.$words[$number % 10]. ' '.$digits[$counter].$plural.' '.$一百; } 否则 $str[] = null; } $Rupees = implode('', array_reverse($str)); $paise = ($decimal > 0) ? “。” . ($words[$decimal / 10] . " " . $words[$decimal % 10]) 。'派塞' : ''; return ($Rupees ? $Rupees . 'Rupees ' : '') 。$派斯; }

方法调用:

echo getIndianCurrency(79855995.19);

输出 七千万九千八十万卢比五万五千九百九十五卢比。一九派塞

于 2014-09-22T06:15:41.047 回答