Time format processing

// Remove the minute-second value of the time
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 ' '}}Copy the code
// Remove the hours and seconds from the time
export const formatDay = item= > {
  if (item) {
    const newItem = moment(item).format('yyyy-MM-DD')
    return newItem
  } else {
    return ' '}}Copy the code
// return the null value -
export const formatX = item= > {
  if (item) {
    return item
  } else {
    return The '-'}}Copy the code
 
// Return a blank value to a space
export const formatSpace = item= > {
  if (item) {
    return item
  } else {
    return '  '}}Copy the code

Digital and small digit processing

// Check whether the value is a numeric value
function isNum(val) {
  // Check if it is number
  if (typeofval ! = ='number') {
    return false
  }
  if (!isNaN(val)) {
    return true
  } else {
    return false}}Copy the code
// Check whether the value is a numeric value
function formatNum(val, digit) {
  // Outlier judgment
  if (val === null || isNaN(val) || val === undefined || val === ' ' || val === ' ') return The '-'
  // A numeric value or string value
  val = parseFloat(val).toFixed(digit)
 
  // Delete the trailing '0'
  if (val.endsWith('0')) {
    val = val.substring(0, val.lastIndexOf('0'))}Copy the code
  // Delete the trailing '.
  if (val.endsWith('. ')) {
    val = val.substring(0, val.lastIndexOf('. '))}return val
}
Copy the code
// Keep one decimal place
export const formatDrp = item= > {
  return formatNum(item, 1)}Copy the code
// Keep two decimal places
export const formatRz = item= > {
  return formatNum(item, 2)}Copy the code
// Keep three significant digits
export const formatW = item= > {
  const dec = 2 // Keep n bits valid (n-1)
  const newItem = parseFloat(item)
  let num = ' '
  if (isNum(newItem) || parseFloat(newItem) === item) {
    const toExponential = newItem.toExponential(dec) // (switch to scientific notation)
    num = Number(toExponential) // To a normal number type
  }
  return num
}
Copy the code