parseInt()
JS-0101249 doAdjustment(
250 document.getElementById('ID_debts').value,
251 document.getElementById('textarea_debts').value,
252 parseInt(document.getElementById('Amount_debts').value),253 document.getElementById('debts'),
254 "debts");
255
240 doAdjustment(
241 document.getElementById('ID_advance').value,
242 document.getElementById('textarea_advance').value,
243 parseInt(document.getElementById('Amount_advance').value),244 document.getElementById('advance'),
245 "advance");
246
231 doAdjustment(
232 document.getElementById('ID_receivables').value,
233 document.getElementById('textarea_receivables').value,
234 parseInt(document.getElementById('Amount_receivables').value),235 document.getElementById('receivables'),
236 "receivables");
237
222 doAdjustment(
223 document.getElementById('ID_prepayment').value,
224 document.getElementById('textarea_prepayment').value,
225 parseInt(document.getElementById('Amount_prepayment').value),226 document.getElementById('payments'),
227 "payments");
228
213 doAdjustment(
214 document.getElementById('ID_accrual').value,
215 document.getElementById('textarea_accrual').value,
216 parseInt(document.getElementById('Amount_accrual').value),217 document.getElementById('accrual'),
218 "accrual");
219
When using the parseInt()
function it is common to omit the second argument, the radix, and let the function try to determine from the first argument what type of number it is.
By default, parseInt()
will autodetect decimal and hexadecimal (via 0x
prefix).
Prior to ECMAScript 5, parseInt()
also autodetected octal literals, which caused problems because many developers assumed a leading 0
would be ignored.
This confusion led to the suggestion that you always use the radix parameter to parseInt()
to eliminate unintended consequences. So instead of doing this:
let num = parseInt("071"); // 57
Do this:
let num = parseInt("071", 10); // 71
ECMAScript 5 changed the behavior of parseInt()
so that it no longer autodetects octal literals and instead treats them as decimal literals.
However, the differences between hexadecimal and decimal interpretation of the first parameter causes many developers to continue using the radix parameter to ensure the string is interpreted in the intended way.
On the other hand, if the code is targeting only ES5-compliant environments passing the radix 10 may be redundant.
In such a case you might want to disallow using such a radix.
let num = parseInt("071");
num = parseInt(someValue);
num = parseInt("071", "abc");
num = parseInt();
let num = parseInt("071", 10);
num = parseInt("071", 8);
num = parseFloat(someValue);