php 格式化金额
/**
* 格式化金额
*
* @param int $money
* @param int $len
* @param string $sign
* @return string
*/
function format_money($money, $len=2, $sign='¥'){
$negative = $money > 0 ? '' : '-';
$int_money = intval(abs($money));
$len = intval(abs($len));
$decimal = '';//小数
if ($len > 0) {
$decimal = '.'.substr(sprintf('%01.'.$len.'f', $money),-$len);
}
$tmp_money = strrev($int_money);
$strlen = strlen($tmp_money);
for ($i = 3; $i < $strlen; $i += 3) {
$format_money .= substr($tmp_money,0,3).',';
$tmp_money = substr($tmp_money,3);
}
$format_money .= $tmp_money;
$format_money = strrev($format_money);
return $sign.$negative.$format_money.$decimal;
}
php 格式化金额的更多相关文章
- php格式化金额函数分享
/** * 格式化金额 * * @param int $money * @param int $len * @param string $sign * @return string */ ...
- js 格式化数字,格式化金额:
js 格式化数字,格式化金额: function number_format(number, decimals, dec_point, thousands_sep) { /* * 参数说明: * nu ...
- JS/Java/Python格式化金额
//java代码 public static void main(String[] args) { DecimalFormat myformat = new DecimalFormat(); ...
- Oracle EBS客户化程序中格式化金额
在Oracle EBS系统中,随处可见金额的显示格式,通常情况下都具有千分位符,同时有一定位数的精度,让我们先来看看一些现成的例子 上面这些列子中的金额都显示了千分位符,同时具备以2位小数,难道 ...
- 用javascript正则表达式来格式化金额
<html><head><script> function a() { var amount = "-22334.334455"; //if(/ ...
- vue 自定义过滤器 格式化金额(保留两位小数)
1.js部分 import Vue from 'vue' Vue.filter('money', function(val) { val = val.toString().replace(/\$|\, ...
- 格式化input输入内容(金额)
项目中要用到格式化金额输入框,要求每三个数字用逗号分割开. 添加一个directive angular.module('myApp.directives', []) .directive('filte ...
- js格式化数字和金额
格式化数字,格式化金额: function number_format(number, decimals, dec_point, thousands_sep) { /* * 参数说明: * numbe ...
- js 金额格式化
//格式化金额 function fmoney(s, n) { n = n > 0 && n <= 20 ? n : 2; s = parseFloat((s + &quo ...
随机推荐
- PHP浮点数引起的四舍五入问题
同事在开发中,遇到一个浮点数问题,过来问我,问题如下: $a = 0.705; $b = 20.795; $c = 20.715; $d = 20.745; echo sprintf('%0.2f', ...
- [Head First Python]3. 文件与异常:处理错误
datafile.txt Man: Is this the right room for an argument? Other Man: I've told you once. Man: No you ...
- Measuring Lengths in Baden
Description Measuring Lengths in Baden time limit per test: 2 seconds memory limit per test: 256 meg ...
- [XMPP]iOS聊天软件学习笔记[一]
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- QCoreApplication::processEvents();的作用与TApplication::ProcessMessages的作用完全相同,但是没想到这种用法还有缺点
手动事件处理 最基本的解决方案是明确要求Qt在计算的某些时刻处理等待事件.要做到这一点,必须定期调用QCoreApplication::processEvents(). 下面的例子显示如何做到这一点: ...
- UrlDownloadFile, 线程下载文件, 带进度条
unit FileDownLoadThread; interface uses Classes, SysUtils, Windows, ActiveX, UrlMon; const S_ABORT = ...
- VS2010常用的调试方法
1.一直以来都没用过command window, F5以后可以这样用,直接对一个函数,或者变量做模块测试 以下还有一些常用的技巧: 1 悬停鼠标查看表达式值 调试是很有挑战性的.比如在函数内逐步运行 ...
- Luci流程分析(openwrt下)
1. 页面请求: 1.1. 代码结构 在openwrt文件系统中,lua语言的代码不要编译,类似一种脚本语言被执行,还有一些uhttpd服务器的主目录,它们是: /www/index.html cgi ...
- OpenWrt compiles
make -r world: build failed. Please re-run make with -j1 V=s to see what's going onmake: *** [world] ...
- 【错误】:Could not open JDBC Connection for transaction; nested exception is: Communications link failure;The last packet sent successfully to the server was 1 milliseconds ago
# #错误日志 2016-11-10 16:19:20,834 ERROR [org.quartz.core.JobRunShell] - Job DEFAULT.jobtask threw an u ...