parseInt returns undefined
Question
Facebook's code changes on Tuesday night have impacted how parseInt
works in FBJS. Where I previously used it to convert decimal numbers to straight integers, now it always returns undefined.
For example:
return parseInt(decimalnum);
no longer works. Anyone figured out how we are supposed to round to integers now? Thanks.
Solution
Thanks for the report. It's fixed on trunk now; it should be out tomorrow unless there's another push later today.
OTHER TIPS
I suspect that decimalnum
is not defined in your function. Try replacing your return with return decimalnum;
-- you may still be returning undefined.
parseInt
is not for rounding - it actually takes the integer component of a number, or coerces a string to be a number. If you want to round, use Math.round
. Depending on your usage, you may find Math.floor
or Math.ceil
useful.
Did you try parseInt(decimalnum, 10);
?