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.
136 lines
3.1 KiB
136 lines
3.1 KiB
function numberFormat(value) {
|
|
// var v = parseInt(value)//强转Int,毕竟有可能返回是String类型的数字
|
|
if (value || value == 0) {
|
|
return Number(value).toFixed(2)
|
|
}
|
|
return ''
|
|
}
|
|
function numberFormat2(value) {
|
|
// var v = parseInt(value)//强转Int,毕竟有可能返回是String类型的数字
|
|
if (value || value == 0) {
|
|
return Number(value).toFixed(2)
|
|
}
|
|
return ''
|
|
}
|
|
function numberFormat3(value) {
|
|
// var v = parseInt(value)//强转Int,毕竟有可能返回是String类型的数字
|
|
if (value) {
|
|
return value.toFixed(3)
|
|
}
|
|
return ''
|
|
}
|
|
function formateMoney(value) {
|
|
// var v = parseInt(value)//强转Int,毕竟有可能返回是String类型的数字
|
|
if (value || value == 0) {
|
|
return (parseFloat(value)).toFixed(2)
|
|
}
|
|
return ''
|
|
}
|
|
function formateWeight(value, kg) {
|
|
if (value || value == 0) {
|
|
if(kg){
|
|
return (parseFloat(value)).toFixed(1) + 'KG'
|
|
} else {
|
|
return (parseFloat(value) / 1000).toFixed(3) + '吨'
|
|
}
|
|
}
|
|
return ''
|
|
}
|
|
function formateWeight3(value) {
|
|
return (parseFloat(value) / 1000).toFixed(1) + '吨'
|
|
}
|
|
function forWeight(value, kg) {
|
|
if (value || value == 0) {
|
|
if(kg){
|
|
return (parseFloat(value)).toFixed(1)
|
|
} else {
|
|
return (parseFloat(value) / 1000).toFixed(3)
|
|
}
|
|
}
|
|
return ''
|
|
}
|
|
function formateAmount(value) {
|
|
if (value || value == 0) {
|
|
return (parseFloat(value)).toFixed(2)
|
|
}
|
|
return ''
|
|
}
|
|
function isEmpty(val) {
|
|
return typeof val === 'undefined' || val === '' || val === null
|
|
}
|
|
function formatePrice(value, kg) {
|
|
if(isEmpty(value)){
|
|
return '- -'
|
|
}
|
|
if (value || value !== 0) {
|
|
if(value < 0){
|
|
value = -value
|
|
}
|
|
if(kg){
|
|
return (parseFloat(value)).toFixed(3)
|
|
} else {
|
|
return (parseFloat(value) * 1000).toFixed(0)
|
|
}
|
|
}
|
|
return '- -'
|
|
}
|
|
function formatePrice2(value, kg) {
|
|
if (value || value !== 0) {
|
|
if(kg){
|
|
return (parseFloat(value)).toFixed(3) + '元/KG'
|
|
} else {
|
|
return (parseFloat(value) * 1000).toFixed(1) + '元/吨'
|
|
}
|
|
}
|
|
return '- -'
|
|
}
|
|
function formateDrice(value) {
|
|
if (value || value == 0) {
|
|
return (parseFloat(value) * 1000).toFixed(0)
|
|
}
|
|
return '- -'
|
|
}
|
|
function substring(str, start, end){
|
|
if(str){
|
|
return str.substring(start, end)
|
|
}
|
|
return ''
|
|
}
|
|
function formateDescripe(value) {
|
|
if (typeof(value) == 'number') {
|
|
return value + '%'
|
|
}
|
|
return '- -'
|
|
}
|
|
function formatePrice3(value, kg) {
|
|
if(isEmpty(value)){
|
|
return ''
|
|
}
|
|
if (value || value !== 0) {
|
|
if(value < 0){
|
|
value = -value
|
|
}
|
|
if(kg){
|
|
return (parseFloat(value)).toFixed(3)
|
|
} else {
|
|
return (parseFloat(value) * 1000).toFixed(0)
|
|
}
|
|
}
|
|
return ''
|
|
}
|
|
module.exports = {
|
|
numberFormat: numberFormat, //暴露接口调用
|
|
numberFormat2: numberFormat2, //暴露接口调用
|
|
numberFormat3: numberFormat3, //暴露接口调用
|
|
formateMoney: formateMoney,
|
|
formateWeight: formateWeight,
|
|
formateWeight3: formateWeight3,
|
|
formateAmount: formateAmount,
|
|
formatePrice: formatePrice,
|
|
formatePrice2: formatePrice2,
|
|
formatePrice3: formatePrice3,
|
|
substring: substring,
|
|
forWeight: forWeight,
|
|
formateDrice: formateDrice,
|
|
formateDescripe: formateDescripe,
|
|
}
|