英文:
How can I use CSS to separate numbers in my application with commas every 3 digits?
问题
在我的应用程序中有许多数字,我想用CSS或SCSS在每3个数字之间用逗号分隔它们。
我在Google上没有找到所需的结果。
有人可以帮我吗?
英文:
There are many numbers in my application and I want separate them with commas every 3 digits by CSS or SCSS.
I haven't found a desired result on Google.
Can anyone help me on this please?
Like:
<span class="number"> 1234567.89 </span>
result:
<span class="number"> 1,234,567.89 </span>
答案1
得分: 2
Sure, here's the translation of the text you provided:
如果你可以使用JavaScript,你可以使用toLocaleString
函数
该函数:1234567.89.toLocaleString()
结果:'1,234,567.89'
英文:
if you can use javascript you can use toLocaleString function
the function: 1234567.89.toLocaleString()
result: '1,234,567.89'
答案2
得分: 0
以下是要翻译的代码部分:
const number = document.querySelector('.number');
const formattedNumber = parseFloat(number.textContent).toLocaleString('en');
number.innerText = formattedNumber;
.number::after {
content: attr(data-number);
}
<span class="number">1234567.89</span>
英文:
Try the following code
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const number = document.querySelector('.number');
const formattedNumber = parseFloat(number.textContent).toLocaleString('en');
number.innerText = formattedNumber;
<!-- language: lang-css -->
.number::after {
content: attr(data-number);
}
<!-- language: lang-html -->
<span class="number">1234567.89</span>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论