Number.parseInt
Number.parseInt() λ©μλλ λ¬Έμμ΄μ λΆμνκ³ νΉμ μ§μλ₯Ό μ¬μ©ν μ μ λλ λ² μ΄μ€μ μ μλ₯Ό μ¬μ©ν μ μλ‘ λ³νν΄ λ°ννλ€.
an integer of the specified radix or base.
function roughScale(x, base) {
const parsed = Number.parseInt(x, base);
if (Number.isNaN(parsed)) return 0;
return parsed * 100;
}
roughScale(' 0xf', 16); // 1500
roughScale('321', 2); // 0Syntax
Number.parseInt(string, [ radix])Parameters
string
λΆμν κ°. λ§μ½ μ΄ μΈμκ° λ¬Έμμ΄μ΄ μλλΌλ©΄ ToString μΆμ μ°μ°μ μ¬μ©νμ¬ λ¬Έμμ΄λ‘ λ³ννλ€. μ΄ λ§€κ°λ³μμ 곡백μ 무μλλ€.
radix (Optional)
string μ΄ νννλ μ μλ₯Ό λνλ΄κ³ μ νλ 2μ 36 μ¬μ΄μ μ§μ (μμ μ§λ² 체κ³μ κΈ°μ€μ΄ λλ κ°) μ‘°μ¬ν΄λΌ defaultλ 10μ΄ μλλ€.
Return value
μ£Όμ΄μ§ string μ λΆμν μ μ, radix κ° 2λ³΄λ€ μκ±°λ 36λ³΄λ€ ν¬κ±°λ νΉμ 첫λ²μ§Έ 곡백 λ¬Έμκ° μλ μ«μλ‘ λ³ν ν μ μλ κ²½μ° NaN μ λ°ννλ€.
Description
Number.parseInt() λ©μλλ parseInt() ν¨μμ κ°μ κΈ°λ₯μ κ°μ§κ³ μλ€.
Number.parseInt() λ ECMAScript 2015μμ μ μ λ²μλ₯Ό λͺ¨λν νκΈ° μν΄μλ€.
Polyfill
Browser compatibility
IEμμλ μ§μμλ¨
Last updated
Was this helpful?