大家好我正在寻找一个用逗号分隔成千上万的脚本和点数小数2与00示例2,800,000.00并且只允许使用0到9和逗号+点
DependencyProperties
我已尝试使用此脚本
<div id="item-post-price" class="item-post-price">
<label class="control-label" for="price">
<?php _e('Price', 'ctg_housing'); ?>
</label>
<?php ItemForm::price_input_text(); ?>
</div>
由于
答案 0 :(得分:0)
我做了一个将值转换为字符串的php函数。
function cnvrt($number)
{
$no = round($number);
$point = round($number - $no, 2) * 100;
$hundred = null;
$digits_1 = strlen($no);
$i = 0;
$str = array();
$wordsWEB = 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) ? $wordsWEB[$number] .
" " . $digits[$counter] . $plural . " " . $hundred
:
$wordsWEB[floor($number / 10) * 10]
. " " . $wordsWEB[$number % 10] . " "
. $digits[$counter] . $plural . " " . $hundred;
} else $str[] = null;
}
$str = array_reverse($str);
$result = implode('', $str);
$points = ($point) ? "." . $wordsWEB[$point / 10] . " " . $wordsWEB[$point = $point % 10] : '';
return $result." rupees only";
}
echo cnvrt(9875);
?>
测试此功能Here.。只需复制并粘贴。
我希望这会有所帮助。
答案 1 :(得分:0)
如果您想显示不同的数字格式,例如德语或英语数字格式,您可以简单地执行以下操作:
switch (lang) {
case "de":
return value.toString().replace(".", "").replace(",", ".");
case "en":
return value.toString().replace(",", "");
}