我想将整数值转换为Indian Numbering system。我将值540000作为输入并获得输出值5.4 Lac,但我想回答5.40 Lac。
我的代码:
<?php
function no_to_words($no)
{
if($no == 0) {
return ' ';
}else {
$n = strlen($no); // 7
switch ($n) {
case 3:
$val = $no/100;
$val = round($val, 2);
$finalval = $val ." Hundred";
break;
case 4:
$val = $no/1000;
$val = round($val, 2);
$finalval = $val ." Thousand";
break;
case 5:
$val = $no/1000;
$val = round($val, 2);
$finalval = $val ." Thousand";
break;
case 6:
$val = $no/100000;
$val = round($val, 2);
$finalval = $val ." Lac";
break;
case 7:
$val = $no/100000;
$val = round($val, 2);
$finalval = $val ." Lac";
break;
case 8:
$val = $no/10000000;
$val = round($val, 2);
$finalval = $val ." Cr";
break;
case 9:
$val = $no/10000000;
$val = round($val, 2);
$finalval = $val ." Cr";
break;
default:
echo "";
}
return $finalval;
}
}
?>
答案 0 :(得分:0)
你的问题不是真正的这个功能,因为数字5.4和5.40是相同的数字,所以你需要在这里应用格式,或者在你使用结果的地方。检查这两个的区别:
echo round(540000/100000, 2);
VS
echo sprintf("%2.2f", round(540000/100000, 2));
第二个将显示2位小数,因为格式中定义了这些小数。如果你使用sprintf,你真的不需要这一轮,它会将数字四舍五入到指定的格式。
echo sprintf("%2.2f", 555555 / 100000);
答案 1 :(得分:-1)
这可能有助于您的期望。
number_format($val/10000000,2); //for Crore convertion