user3326265
user3326265

Reputation: 257

parseInt method in javascript returns wrong values

I have parsing values to integer in my function using parseInt, but when i parse the -4.450217635509901e-7 to integer it returns -4.

parseInt(-4.450217635509901e-7)=> -4

-4.450217635509901e-7 is nothing but -0.000000450217635509901 so it should return 0 but for me its returning -4.

How to parse the values having exponential?

Upvotes: 3

Views: 649

Answers (1)

potato
potato

Reputation: 367

parseInt parses a string as an integer. You are giving it a float (I don't even know why that is working). If you want to round it, use your choice of rounding methods from the Math object.

Upvotes: 2

Related Questions