Skip to content
Advertisement

Tag: parseint

What am doing wrong in here?

Input value always gets into if condition first even am parsing it to parseInt() and when page refreshed with a number it gets into else condition, like its not registering the inputValue at first place, also if i add a submit event rather an click one event doesnt fires up. Answer You’re recording the value of the input on page

Javascript Filter integers

I’m learning javascript on FreecodeCamp. And, the solution of my problem doesn’t help me more. We have to filter integers in an array which is saved in const variable. and I cannot understand really this part num % parseInt(num) === 0 ).map( (num) => Math.pow(num, 2) ); Why using parseint() method and Math.pow. Someone could explain me why? thanks. Answer

parseFloat() from the middle of the string

I always have a “NaN” when wanted to “parseInt or parseFloat” from string like “Sometext 330” and it will return “NaN” but i need integer or float 330 Answer You could sanitize your string first so only digit’s remain in the string before parsing the number. edit: now it’s even safer as it will accept Number types without blowing up.

parseInt() parses number literals with exponent incorrectly

I have just observed that the parseInt function doesn’t take care about the decimals in case of integers (numbers containing the e character). Let’s take an example: -3.67394039744206e-15 I expected that the parseInt will also return 0. What’s going on at lower level? Why does parseInt return 3 in this case (some snippets from the source code would be appreciated)?

Advertisement