【问题标题】:html element to javascripthtml元素到javascript
【发布时间】:2021-08-13 22:00:32
【问题描述】:

我只是想为货币符号添加一种样式。但是,它在页面上呈现时看起来很奇怪。而且我只想更改一个看起来很奇怪的符号的样式。

【问题讨论】:

  • 如何将它绑定到 html?请提供您的 html 模板文件代码。

标签: javascript html reactjs react-native object


【解决方案1】:

使用$登录format()

numeral.register('locale', 'btc', {
  delimiters: {
    thousands: ',',
    decimal: '.'
  },
  abbreviations: {
    thousand: 'k',
    million: 'm',
    billion: 'b',
    trillion: 't'
  },
  ordinal(number) {
    const b = number % 10;
    return (~~(number % 100 / 10) === 1) ? 'th' :
      (b === 1) ? 'st' :
      (b === 2) ? 'nd' :
      (b === 3) ? 'rd' : 'th';
  },
  currency: {
    symbol: '<span>฿</span>'
  }
});

numeral.locale('btc');

var number = numeral(1000);

console.log(number.format('$0,0.00'))
&lt;script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"&gt;&lt;/script&gt;

但推荐的做法是custom-formats

numeral.register('locale', 'btc', {
  delimiters: {
    thousands: ',',
    decimal: '.'
  },
  abbreviations: {
    thousand: 'k',
    million: 'm',
    billion: 'b',
    trillion: 't'
  },
  ordinal(number) {
    const b = number % 10;
    return (~~(number % 100 / 10) === 1) ? 'th' :
      (b === 1) ? 'st' :
      (b === 2) ? 'nd' :
      (b === 3) ? 'rd' : 'th';
  },
  currency: {
    symbol: '฿'
  }
});

numeral.register('format', 'btc', {
  regexps: {
    format: /(BTC)/,
    unformat: /(BTC)/
  },
  format: function(value, format, roundingFunction) {
    var space = numeral._.includes(format, ' BTC') ? ' ' : '',
      output;

    value = value * 100;

    // check for space before %
    format = format.replace(/\s?\BTC/, '');

    output = numeral._.numberToFormat(value, format, roundingFunction);

    return '<span>฿</span>' + output;
  },
  unformat: function(string) {
    return numeral._.stringToNumber(string) * 0.01;
  }
});

numeral.locale('btc');

var number = numeral(1000);

console.log(number.format('$0'))
console.log(number.format('BTC0'))
&lt;script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"&gt;&lt;/script&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    • 2019-07-29
    • 1970-01-01
    相关资源
    最近更新 更多