Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 788171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:19:09+00:00 2026-05-14T21:19:09+00:00

parseInt(7em, 10); returns 7 in all browsers I tested [*]. But can I rely

  • 0

parseInt("7em", 10); returns 7 in all browsers I tested [*]. But can I rely on this?

The reason I ask is, that I want to perform some calculations based on em, like

/* elem1.style.top uses em units */
elem2.style.top = parseInt(elem1.style.top, 10) + 1 + "em";

I could do this with regular expressions, but parseInt is easier to use, and probably a bit faster. Or is there another solution (maybe using jQuery)?

[*] Tested so far on: IE 6, IE 8, Safari 4, Firefox 3.6, Opera 10.5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:19:09+00:00Added an answer on May 14, 2026 at 9:19 pm

    That is the behavior according to the standard. ECMA-262 section 15.1.2.2 states that

    parseInt may interpret only a leading portion of string as an integer value; it ignores any characters that cannot be interpreted as part of the notation of an integer, and no indication is given that any such characters were ignored.

    I’d be more worried that at some point in the future the units of elem2.style.top will change. In that case, this code could be turning 200px into 200em, which could cause a great deal of confusion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code works in FF, but not in IE: parseInt($('.scroller').css('left'); In FF it returns
y851sq2vh4pf.to_i(36) #4504900070017571091 but parseInt(y851sq2vh4pf,36) //4504900070017571300 How can I implement the Ruby to_i(36) function in
Integer.parseInt(ff8ca87c, 16); This gives me a NumberFormatException for some reason. Do you know why
I just want to properly translate this foo.push((000 + parseInt(foo1.charAt(loc3), 16).toString(2)).slice(-4)); into php. Anyone
I put this on the head section var d = parseInt(document.getElementById('test').style.width); alert(d); But the
$('#fCount' + folderID).html(parseInt($('#fCount' + folderID).html()) + E); That works, but whatever I try such
I was using parseInt() to get some big prime numbers, but it's working as
if(str.contains(final)) { id = Integer.parseInt(str.substring(18, str.length() - 6)); } System.out.println(id); This line of code
Simple question - How do I convert a string that has been through parseInt
Why does this part of code fail: Integer.parseInt(11000000000000000000000000000000,2); Exception in thread main java.lang.NumberFormatException: For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.