Call me Ishmael.

Javascript

MEMO

%02d 형태 포맷 Javascript에서 쓰기

String.prototype.padStart()

1var string = "n"
2string.padStart(길이, "0")

→ Result : 0n

가격 표시하기

 1toLocaleString()
 2toLocaleString(locales)
 3toLocaleString(locales, options)
 4
 5var number = 123456.789;
 6
 7// request a currency format
 8console.log(number.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' }));
 9// → 123.456,79 €
10
11// the Japanese yen doesn't use a minor unit
12console.log(number.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' }))
13// → ¥123,457
14
15// limit to three significant digits
16console.log(number.toLocaleString('en-IN', { maximumSignificantDigits: 3 }));
17// → 1,23,000
18
19// Use the host default language with options for number formatting
20var num = 30000.65;
21console.log(num.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}));
22// → "30,000.65" where English is the default language, or
23// → "30.000,65" where German is the default language, or
24// → "30 000,65" where French is the default language

천의 자리 단위로 쉼표 끊어줄 때 사용.

10000000 → 10,000,000

문자열 텍스트인 경우 parseInt 를 거쳐야 한다.