import _ from 'lodash'

export const toLocaleString = (value) => {
  if (!value) return 0
  const number = Number(value)
  return _.isNaN(number) ? 0 : number.toLocaleString(undefined, {
    minimumFractionDigits: 0,
    maximumFractionDigits: 2
  })
}

export const toLocaleStringDecimal = (value) => {
  if (!value) return 0.00
  const number = Number(value)
  return _.isNaN(number) ? 0.00 : number.toLocaleString(undefined, {
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
  })
}

export default {
  toLocaleString,
  toLocaleStringDecimal
}
