时间格式处理
export const formatTM = item => {
if (item) {
let newItem = item.replace(':00.0', '')
if (newItem.indexOf('.') > 0) {
newItem = newItem.substr(0, 16)
}
return newItem
} else {
return ''
}
}
export const formatDay = item => {
if (item) {
const newItem = moment(item).format('yyyy-MM-DD')
return newItem
} else {
return ''
}
}
export const formatX = item => {
if (item) {
return item
} else {
return '-'
}
}
export const formatSpace = item => {
if (item) {
return item
} else {
return ' '
}
}
数字小数位处理
function isNum(val) {
if (typeof val !== 'number') {
return false
}
if (!isNaN(val)) {
return true
} else {
return false
}
}
function formatNum(val, digit) {
if (val === null || isNaN(val) || val === undefined || val === '' || val === ' ') return '-'
val = parseFloat(val).toFixed(digit)
if (val.endsWith('0')) {
val = val.substring(0, val.lastIndexOf('0'))
}
if (val.endsWith('.')) {
val = val.substring(0, val.lastIndexOf('.'))
}
return val
}
export const formatDrp = item => {
return formatNum(item, 1)
}
export const formatRz = item => {
return formatNum(item, 2)
}
export const formatW = item => {
const dec = 2
const newItem = parseFloat(item)
let num = ''
if (isNum(newItem) || parseFloat(newItem) === item) {
const toExponential = newItem.toExponential(dec)
num = Number(toExponential)
}
return num
}