Example #1
0
function numberFromView(str, options, symbol = '') {
  if (str === '')
    return undefined;

  const culture = cultureFormats[options.culture || defaultCulture];

  const nb = accounting.unformat(str, handleDefault(options.decimal, culture.decimal));

  if (nb === 0 && Number(str.replace(',', '.').replace(symbol, '')) !== 0)
    return str;

  return nb;
}
Example #2
0
  toView(value, options) {
    if (+value !== value)
      return value;

    const culture = cultureFormats[options.culture || defaultCulture];

    var res = accounting.formatNumber(
      value,
      handleDefault(options.precision, culture.precision, 0),
      handleDefault(options.thousand, culture.thousand, ''),
      handleDefault(options.decimal, culture.decimal)
    );

    if (options.symbol)
      return (handleDefault(culture.unitFormat, '%v %s').replace('%v', res).replace('%s', options.symbol));

    return res;
  }