troubleshooting Question

Javascript to Sum Decimal Numbers

Avatar of doctorbill
doctorbillFlag for United Kingdom of Great Britain and Northern Ireland asked on
JavaScriptHTML
8 Comments3 Solutions94 ViewsLast Modified:
 <script type="text/javascript">
                function addNumbers()
                {
                        var val1 = parseInt(document.getElementById("timepicker").value);
                        var val2 = parseInt(document.getElementById("timepicker2").value);
                        var ansD = document.getElementById("answer");
                        ansD.value = val2 - val1;
                }
        </script>

<input type="button" name="Sumbit" value="Click here to calculate Time Spent" onclick="javascript:addNumbers()"/>
        Answer = <input type="text" id="answer" name="answer" value=""/>

The above code works for me when I use integers but how do I set it to be able to use decimal numbers as inputs from the textboxes and give the result as decimal
ASKER CERTIFIED SOLUTION
Zakaria Acharki
Analyst Developer
Join our community to see this answer!
Unlock 3 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros