5
A
回答
5
這裏的功能:
function formatInIndianStyle($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;
}
0
入住這plugin- http://archive.plugins.jquery.com/project/numberformatter
這裏是你如何使用這個插件的例子。
$("#salary").blur(function(){
$(this).parseNumber({format:"#,###.00", locale:"us"});
$(this).formatNumber({format:"#,###.00", locale:"us"});
});
只要改變區域..
更多例子和信息visit- http://code.google.com/p/jquery-numberformatter/
我的例子來源:http://code.google.com/p/jquery-numberformatter/
希望這有助於:)
0
這裏是另一個解決方案僅供參考:
<?php
# Output easy-to-read numbers
# by james at bandit.co.nz
function bd_nice_number($n) {
// first strip any formatting;
$n = (0+str_replace(",","",$n));
// is this a number?
if(!is_numeric($n)) return false;
// now filter it;
if($n>1000000000000) return round(($n/1000000000000),1).' trillion';
else if($n>1000000000) return round(($n/1000000000),1).' billion';
else if($n>1000000) return round(($n/1000000),1).' million';
else if($n>1000) return round(($n/1000),1).' thousand';
return number_format($n);
}
?>
0
<?php //Credits are going to: @Niet-the-Dark-Absol
function indian_number_format($num){
$num=explode('.',$num);
$dec=(count($num)==2)?'.'.$num[1]:'.00';
$num = (string)$num[0];
if(strlen($num) < 4) return $num;
$tail = substr($num,-3);
$head = substr($num,0,-3);
$head = preg_replace("/\B(?=(?:\d{2})+(?!\d))/",",",$head);
return $head.",".$tail.$dec;
}
?>
問題:從PHP手冊stackoverflow.com/questions/10042485
相關問題
- 1. 未格式化貨幣格式貨幣
- 2. PHP貨幣格式
- 3. 格式貨幣
- 4. 貨幣格式
- 5. 貨幣格式
- 6. C#格式十進制貨幣/貨幣
- 7. 根據貨幣代碼將貨幣格式設置爲貨幣
- 8. 用PHP打印貨幣數字格式
- 9. PHP數字格式(貨幣)
- 10. 帶貨幣符號的PHP貨幣格式
- 11. PHP的貨幣格式不顯示貨幣符號
- 12. Sencha貨幣格式
- 13. 數/貨幣格式
- 14. 貨幣格式C++
- 15. C#貨幣格式
- 16. C#格式貨幣
- 17. Javascript貨幣格式
- 18. 格式化貨幣
- 19. 格式化貨幣
- 20. ZF2貨幣格式
- 21. 貨幣laravel格式
- 22. 貨幣格式laravel
- 23. 格式化貨幣
- 24. INR貨幣格式
- 25. 的Javascript貨幣格式
- 26. .NET中的貨幣格式
- 27. c中的貨幣格式#
- 28. OpenXML中的貨幣格式
- 29. Gridview中的貨幣格式
- 30. KendoGrid中的貨幣格式
串money_format(字符串$格式,浮$號)? – PurplePilot 2011-12-18 08:19:34
澄清:你是否試圖將'7,57,800'轉換爲'7.57 Lakhs'?或試圖將'757800'轉換爲'7,57800'? – 2011-12-18 08:59:46