將數字轉換成三位逗號分隔的樣式
1
code:
2
//將數字轉換成三位逗號分隔的樣式
3
function formatNum(a){
4
var b = parseFloat(a);
5
var tempConvert = b.toLocaleString();
6
if (tempConvert.charAt(0) == "."){
7
tempConvert = 0+tempConvert;
8
}
9
return tempConvert;
10
}
11
12
test:120025874.3295
13
14
alert(formatNum(120025874.3295));
15

2

3

4

5

6

7

8

9

10

11

12

13

14

15

這是一個javascript格式化數字的一個例子