77 lines
2.0 KiB
XML
77 lines
2.0 KiB
XML
// 金额格式化
|
||
var moneyFormat = function(num) {
|
||
if (null == "") {
|
||
return ""
|
||
}
|
||
num = parseFloat((num + "").replace('/[^\d\.-]/g', "")).toFixed(2) + "";
|
||
var integ = num.split(".")[0].split("").reverse(),
|
||
deci = num.split(".")[1];
|
||
var space = "";
|
||
for (i = 0; i < integ.length; i++) {
|
||
space += integ[i] + ((i + 1) % 3 == 0 && (i + 1) != integ.length ? "," : "");
|
||
}
|
||
var text = space.split("").reverse().join("") + "." + deci;
|
||
if (text.substring(text.length - 3) == ".00") {
|
||
text = text.substring(0, text.length - 3)
|
||
} else if (text.substring(text.length - 1) == "0") {
|
||
text = text.substring(0, text.length - 1)
|
||
}
|
||
return text
|
||
}
|
||
// 字符串截取
|
||
var sub = function(val, num) {
|
||
if (val.length == 0 || val == undefined) {
|
||
return;
|
||
}
|
||
if (val.length > num) {
|
||
return val.substring(0, num) + "...";
|
||
} else {
|
||
return val;
|
||
}
|
||
}
|
||
var sex = function(type) {
|
||
return type ? '男' : '女'
|
||
}
|
||
var formatSeconds = function(value) {
|
||
var theTime = parseInt(value); // 秒
|
||
var theTime1 = 0; // 分
|
||
var theTime2 = 0; // 小时
|
||
if (theTime > 60) {
|
||
theTime1 = parseInt(theTime / 60);
|
||
theTime = parseInt(theTime % 60);
|
||
if (theTime1 > 60) {
|
||
theTime2 = parseInt(theTime1 / 60);
|
||
theTime1 = parseInt(theTime1 % 60);
|
||
}
|
||
}
|
||
|
||
var result = "" + parseInt(theTime); //秒
|
||
if (10 > theTime > 0) {
|
||
result = "0" + parseInt(theTime); //秒
|
||
} else {
|
||
result = "" + parseInt(theTime); //秒
|
||
}
|
||
|
||
if (10 > theTime1 > 0) {
|
||
result = "0" + parseInt(theTime1) + ":" + result; //分,不足两位数,首位补充0,
|
||
} else {
|
||
result = "" + parseInt(theTime1) + ":" + result; //分
|
||
}
|
||
if (theTime2 > 0) {
|
||
result = "" + parseInt(theTime2) + ":" + result; //时
|
||
}
|
||
return result;
|
||
}
|
||
var strFormatObj= function(val){
|
||
return JSON.parse(val)
|
||
}
|
||
var parseIntFormat = function(val){
|
||
return parseInt(val)
|
||
}
|
||
module.exports = {
|
||
moneyFormat: moneyFormat,
|
||
sub: sub,
|
||
formatSeconds: formatSeconds,
|
||
strFormatObj: strFormatObj,
|
||
parseIntFormat: parseIntFormat
|
||
} |