You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.0 KiB
114 lines
3.0 KiB
var numberUtil = {
|
|
numberFormat: function (value) {
|
|
// var v = parseInt(value)//强转Int,毕竟有可能返回是String类型的数字
|
|
if (value || value == 0) {
|
|
return Number(value).toFixed(2)
|
|
}
|
|
return ''
|
|
},
|
|
numberFormat2: function (value) {
|
|
// var v = parseInt(value)//强转Int,毕竟有可能返回是String类型的数字
|
|
if (value || value == 0) {
|
|
return Number(value).toFixed(2)
|
|
}
|
|
return ''
|
|
},
|
|
numberFormat3: function (value) {
|
|
// var v = parseInt(value)//强转Int,毕竟有可能返回是String类型的数字
|
|
if (value) {
|
|
return value.toFixed(3)
|
|
}
|
|
return ''
|
|
},
|
|
formateMoney: function (value) {
|
|
// var v = parseInt(value)//强转Int,毕竟有可能返回是String类型的数字
|
|
if (value || value == 0) {
|
|
return (parseFloat(value)).toFixed(2)
|
|
}
|
|
return ''
|
|
},
|
|
formateWeight: function (value, kg) {
|
|
if (value || value == 0) {
|
|
if(kg){
|
|
return (parseFloat(value)).toFixed(1) + 'KG'
|
|
} else {
|
|
return (parseFloat(value) / 1000).toFixed(3) + '吨'
|
|
}
|
|
}
|
|
return ''
|
|
},
|
|
formateWeight3: function (value) {
|
|
return (parseFloat(value) / 1000).toFixed(1) + '吨'
|
|
},
|
|
forWeight: function (value, kg) {
|
|
if (value || value == 0) {
|
|
if(kg){
|
|
return (parseFloat(value)).toFixed(1)
|
|
} else {
|
|
return (parseFloat(value) / 1000).toFixed(3)
|
|
}
|
|
}
|
|
return ''
|
|
},
|
|
formateAmount: function (value) {
|
|
if (value || value == 0) {
|
|
return (parseFloat(value)).toFixed(2)
|
|
}
|
|
return ''
|
|
},
|
|
formatePrice: function (value, kg) {
|
|
if (value || value == 0) {
|
|
if(kg){
|
|
return (parseFloat(value)).toFixed(3)
|
|
} else {
|
|
return (parseFloat(value) * 1000).toFixed(1)
|
|
}
|
|
}
|
|
return ''
|
|
},
|
|
formatePrice2: function (value, kg) {
|
|
if (value || value == 0) {
|
|
if(kg){
|
|
return (parseFloat(value)).toFixed(3) + '元/KG'
|
|
} else {
|
|
return (parseFloat(value) * 1000).toFixed(1) + '元/吨'
|
|
}
|
|
}
|
|
return ''
|
|
},
|
|
formateDrice: function (value) {
|
|
if (value || value == 0) {
|
|
return (parseFloat(value) * 1000).toFixed(0)
|
|
}
|
|
return '- -'
|
|
},
|
|
substring: function(str, start, end){
|
|
if(str){
|
|
return str.substring(start, end)
|
|
}
|
|
return ''
|
|
},
|
|
formateDescripe: function (value) {
|
|
if (typeof(value) == 'number') {
|
|
return value + '%'
|
|
}
|
|
return '- -'
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
numberFormat: numberUtil.numberFormat, //暴露接口调用
|
|
numberFormat2: numberUtil.numberFormat2, //暴露接口调用
|
|
numberFormat3: numberUtil.numberFormat3, //暴露接口调用
|
|
formateMoney: numberUtil.formateMoney,
|
|
formateWeight: numberUtil.formateWeight,
|
|
formateWeight3: numberUtil.formateWeight3,
|
|
formateAmount: numberUtil.formateAmount,
|
|
formatePrice: numberUtil.formatePrice,
|
|
formatePrice2: numberUtil.formatePrice2,
|
|
substring: numberUtil.substring,
|
|
forWeight: numberUtil.forWeight,
|
|
formateDrice: numberUtil.formateDrice,
|
|
formateDescripe: numberUtil.formateDescripe,
|
|
}
|