wahsaga: parseInt("08") = 0 ??

Beitrag lesen

hi,

Warum ergibt parseInt("08") nicht 8?

javascript:alert(parseInt('07'));  --> 7
javascript:alert(parseInt('08'));  --> 0

weil zahlen mit führender null in javascript oktalzahlen sind.

zusätzliche angabe der basis des zahlensystems schafft abhilfe ->
parseInt('08', 10)

gruß,
wahsaga

--
"Look, that's why there's rules, understand? So that you _think_ before you break 'em."