javascript - Number Format on Array of Int Jquery
问题描述
I have an array look like these :
console.log(myArray);
myArray: [100000, 300000, 20000000, 3450000, 610000]
What I want to do is converting my array into like these:
myArray: [100.000, 300.000, 20.000.000, 3.450.000, 610.000]
So far, I've tried code:
for (let i = 0; i < myArray.length; i++) {
const element = (myArray[i]/1000).toFixed(3);
}
console.log(element);
But it seems didn't work at all. Anyone can help me to solve these?
Thanks.
解决方案
您可以使用Intl.NumberFormat
与所需输出匹配的语言环境(例如德语/德国):
const array = [100000, 300000, 20000000, 3450000, 610000];
const formatter = new Intl.NumberFormat('de-DE');
const formatted = array.map(formatter.format);
console.log(formatted);
推荐阅读
- python - 如何根据数据框的行值作为子字符串/包含在另一个数据框的行值中来连接两个数据框?
- python - 删除所有子域并仅获取根域 pyspark
- python-3.x - Python Card & Deck OOP
- php - 在 api 调用的结果中匹配 Urls
- javascript - 裁剪图像 url 作为道具 React
- docker - 卷不适用于 Datapower 和 docker
- computational-geometry - 在 OpenMesh 中哪里存储 VertexHandle 的 id?
- c++ - 8 各种棋子的皇后象棋问题
- java - 当我将 fx:controller 添加到 fxml 文件时出现错误
- javascript - 在 Javascript 中进行表单验证