packages/ui-i18n/src/Decimal.js
function _format (input, locale) {
  locale = locale || Locale.browserLocale() // eslint-disable-line no-param-reassign

  let result = input

  const { thousands, decimal } = Decimal.getDelimiters(locale)
  const isNegative = (result[0] === '-')

  // remove all characters except for digits and decimal delimiters
  result = result.replace(new RegExp(`[^\\d\\${decimal}]`, 'g'), '')

  // remove all decimal delimiters except for the last one if present
  result = result.replace(new RegExp(`[${decimal}](?=.*[${decimal}])`, 'g'), '')

  // remove the leading zeros using positive lookahead
  result = result.replace(new RegExp(`^[0${thousands}]+(?=\\d|0${decimal})`, ''), '')

  // add leading zero to decimal, if not present
  result = result.charAt(0) === decimal ? result.replace(/^/, '0') : result

  const parts = result.split(decimal)
  const thousandSections = []

  let curr = parts[0]
  while (curr.length > 0) {
    thousandSections.unshift(curr.substr(Math.max(0, curr.length - 3), 3))
    curr = curr.substr(0, curr.length - 3)
  }

  result = thousandSections.join(thousands)

  if (parts[1]) {
    result = `${result}${decimal}${parts[1]}`
  }

  if (isNegative && result) {
    result = `-${result}`
  }

  return result
}
function _format (input, locale) {
  locale = locale || Locale.browserLocale() // eslint-disable-line no-param-reassign

  let result = input

  const { thousands, decimal } = Decimal.getDelimiters(locale)
  const isNegative = (result[0] === '-')

  // remove all characters except for digits and decimal delimiters
  result = result.replace(new RegExp(`[^\\d\\${decimal}]`, 'g'), '')

  // remove all decimal delimiters except for the last one if present
  result = result.replace(new RegExp(`[${decimal}](?=.*[${decimal}])`, 'g'), '')

  // remove the leading zeros using positive lookahead
  result = result.replace(new RegExp(`^[0${thousands}]+(?=\\d|0${decimal})`, ''), '')

  // add leading zero to decimal, if not present
  result = result.charAt(0) === decimal ? result.replace(/^/, '0') : result

  const parts = result.split(decimal)
  const thousandSections = []

  let curr = parts[0]
  while (curr.length > 0) {
    thousandSections.unshift(curr.substr(Math.max(0, curr.length - 3), 3))
    curr = curr.substr(0, curr.length - 3)
  }

  result = thousandSections.join(thousands)

  if (parts[1]) {
    result = `${result}${decimal}${parts[1]}`
  }

  if (isNegative && result) {
    result = `-${result}`
  }

  return result
}
function _format ( input , locale ) { locale = locale || Locale . browserLocale ( ) // eslint-disable-line no-param-reassign let result = input const { thousands , decimal } = Decimal . getDelimiters ( locale ) const isNegative = ( result [ 0 ] === '-' ) // remove all characters except for digits and decimal delimiters result = result . replace ( new RegExp ( ` \\ \\ ${ decimal } ` , 'g' ) , '' ) // remove all decimal delimiters except for the last one if present result = result . replace ( new RegExp ( ` ${ decimal } ${ decimal } ` , 'g' ) , '' ) // remove the leading zeros using positive lookahead result = result . replace ( new RegExp ( ` ${ thousands } \\ ${ decimal } ` , '' ) , '' ) // add leading zero to decimal, if not present result = result . charAt ( 0 ) === decimal ? result . replace ( / ^ / , '0' ) : result const parts = result . split ( decimal ) const thousandSections = [ ] let curr = parts [ 0 ] while ( curr . length > 0 ) { thousandSections . unshift ( curr . substr ( Math . max ( 0 , curr . length - 3 ) , 3 ) ) curr = curr . substr ( 0 , curr . length - 3 ) } result = thousandSections . join ( thousands ) if ( parts [ 1 ] ) { result = ` ${ result } ${ decimal } ${ parts [ 1 ] } ` } if ( isNegative && result ) { result = ` ${ result } ` } return result }
Cleans up the string given and applies the thousands delimiter Doesn't take into account chinese and indian locales with non-standard grouping This will be addressed in INSTUI-996
Cleans up the string given and applies the thousands delimiter Doesn t take into account chinese and indian locales with non - standard grouping This will be addressed in INSTUI - 996