栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在PHP中以印度数字格式显示货币

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在PHP中以印度数字格式显示货币

您有很多选择,但

money_format
可以为您解决问题。

例:

$amount = '100000';setlocale(LC_MONETARY, 'en_IN');$amount = money_format('%!i', $amount);echo $amount;

输出:

1,00,000.00

注意:

仅在系统具有strfmon功能时才定义 money_format() 函数。例如,Windows没有,因此Windows中未定义
money_format()

纯PHP实现-在任何系统上均可使用:

$amount = '10000034000';$amount = moneyFormatIndia( $amount );echo $amount;function moneyFormatIndia($num) {    $explrestunits = "" ;    if(strlen($num)>3) {        $lastthree = substr($num, strlen($num)-3, strlen($num));        $restunits = substr($num, 0, strlen($num)-3); // extracts the last three digits        $restunits = (strlen($restunits)%2 == 1)?"0".$restunits:$restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping.        $expunit = str_split($restunits, 2);        for($i=0; $i<sizeof($expunit); $i++) { // creates each of the 2's group and adds a comma to the end if($i==0) {     $explrestunits .= (int)$expunit[$i].","; // if is first value , convert into integer } else {     $explrestunits .= $expunit[$i].","; }        }        $thecash = $explrestunits.$lastthree;    } else {        $thecash = $num;    }    return $thecash; // writes the final format where $currency is the currency symbol.}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/465911.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号