Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

Basic Javascript Help

I have some basic HTML and assigned an ID

<div id="somecontent">48793748</div>

I want to find the number value of the div

so I know its something like

document.getElementById("somecontent")

I need to assign a variable and end up with the value being a number

If I do a document.getElementById("somecontent").innerHTML
I get "48793748" but its a string not a number.  How do I convert or change the getElementById so that it returns a number?
0
Baub Eis
Asked:
Baub Eis
  • 3
  • 3
1 Solution
 
GaryCommented:
parseInt(document.getElementById("somecontent").innerHTML)
0
 
Baub EisAuthor Commented:
that drops info past the decimal point.

39.000329 returns 39

How can I get it to return the value of 39.000329 from the element?
0
 
GaryCommented:
parseFloat(document.getElementById("somecontent").innerHTML)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Baub EisAuthor Commented:
parseFloat got it
0
 
Baub EisAuthor Commented:
so can I assign a variable with it?

var myvar = parseFloat(document.getElementById("somecontent.innerHTML)

?
0
 
GaryCommented:
Yep
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now