-1

我正在制作房地产门户网站。在该用户输入的财产价值中,如 55,00,000 - 45,35,000 - 30,00,000 等等。我的问题是,我想将这些值显示为 55 Lac(s) - 45.35 Lac(s) - 30 Lac(s) 等等。所以请..建议我,我怎样才能做到这一点。

谢谢

4

6 回答 6

3

你可以money_format()在php中使用函数。http://php.net/manual/en/function.money-format.php

money_format()在窗口中使用,如果你有 Intl 扩展名,你可以使用

http://de.php.net/manual/en/numberformatter.formatcurrency.php — 根据格式化程序规则格式化货币值。手册中的示例

$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
$fmt = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";

输出

1.234.567,89 €
1.234.567,89 RUR
1 234 567,89€
1 234 567,89р.

另请参阅我关于如何将格式化的货币字符串解析回浮点数的答案:

于 2013-08-01T06:10:17.577 回答
1

对于正常情况来说,money_format 是理想的选择,但您需要使用类似“Lac”的格式。您需要根据条件编写自己的代码。

首先从用户输入的金额中删除所有逗号。像那样

$number = str_replace(',', '', $number);

然后检查并制作所需的字符串。

if($number > 10000000)
{
    $num = ((float)$number) / 10000000;
    $num = $num.' Crore(s)'
}
else if($number > 100000)
{
    $num = ((float)$number) / 100000;
    $num = $num.' Lac(s)'
}
else if($number > 1000)
{
    $num = ((float)$number) / 1000;
    $num = $num.' Thousand(s)'
}
于 2013-08-01T06:24:46.133 回答
0

在这里寻找 Zend 框架和核心 php在这里

string money_format ( string $format , float $number )
于 2013-08-01T06:12:05.650 回答
0

你可以使用这个功能

function formatInCurrencyStyle($num){
     $pos = strpos((string)$num, ".");
     if ($pos === false) {
        $decimalpart="00";
     }
     if (!($pos === false)) {
        $decimalpart= substr($num, $pos+1, 2); $num = substr($num,0,$pos);
     }

     if(strlen($num)>3 & strlen($num) <= 12){
         $last3digits = substr($num, -3 );
         $numexceptlastdigits = substr($num, 0, -3 );
         $formatted = makeComma($numexceptlastdigits);
         $stringtoreturn = $formatted.",".$last3digits.".".$decimalpart ;
     }elseif(strlen($num)<=3){
        $stringtoreturn = $num.".".$decimalpart ;
     }elseif(strlen($num)>12){
        $stringtoreturn = number_format($num, 2);
     }

     if(substr($stringtoreturn,0,2)=="-,"){
        $stringtoreturn = "-".substr($stringtoreturn,2 );
     }

     return $stringtoreturn;
 }

 function makeComma($input){ 
     if(strlen($input)<=2)
     { return $input; }
     $length=substr($input,0,strlen($input)-2);
     $formatted_input = makeComma($length).",".substr($input,-2);
     return $formatted_input;
 }
于 2013-08-01T06:12:53.083 回答
0

使用number_format: http: //php.net/manual/en/function.number-format.php

$english_format_number = number_format($number, 2, '.', ',');

您也可以使用money_format: http: //php.net/manual/en/function.money-format.php

Note:

The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows.

Note:

The LC_MONETARY category of the locale settings, affects the behavior of this function. Use setlocale() to set to the appropriate default locale before using this function. 
于 2013-08-01T06:20:45.827 回答
0

用一个简单的方法

number_format(200000)  // 200,000
于 2013-11-07T06:37:10.570 回答