Solving a Mystery Behavior of parseInt() in JavaScript
Read OriginalThis article investigates the puzzling result of parseInt(0.0000005) returning 5 in JavaScript. It details how parseInt() converts its argument to a string, revealing that very small numbers use exponential notation (e.g., '5e-7'), and parseInt() then parses only the leading digit. The post provides a clear technical explanation and recommends using Math.floor() for safe integer extraction.
Comments
No comments yet
Be the first to share your thoughts!
Browser Extension
Get instant access to AllDevBlogs from your browser