how do I split a decimal number?

Posted on 2008-11-18
Last Modified: 2012-08-13
I have input boxes with the total hours for one given project and total hours worked for that day. I took the hours and minutes and split them up. I am trying to take the minutes and divide them by 60 to get the hour on the left side of the decimal and the minutes on the other side of the decimal that I plan to multiply by .06 to get the total minutes, but I cannot seem to get past the point of getting the decimal.

the code I need to get working is

var newMin = totMins2.split(".");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<script language=javascript>

          function calculate(){

			   //var new3 = total2.Length;

			   //var newh = parseInt(new2.substring(0,2));

			   //var newm2 = parseInt(total2[1].substring(0,5));


			   var strNum = document.getElementById("timeTot").value;

			   var findColon = strNum.indexOf(':');


			   if (findColon<=1)


			   strNum = "0" + strNum;

			   var getMin = strNum.substring(findColon + 2, 5);




			   var getMin = strNum.substring(findColon + 1, 5);


			   var getHour = strNum.substring(0, 2);




			   var strNum2 = document.getElementById("dailyTot").value;

			   var findColon2 = strNum2.indexOf(':');


			   if (findColon2<=1)


			   strNum2 = "0" + strNum2;

			   var getMin2 = strNum2.substring(findColon2 + 2, 5);




			   var getMin2 = strNum2.substring(findColon2 + 1, 5);



			   var getHour2 = strNum2.substring(0, 2);




			   var totHours = parseInt(getHour*1) + parseInt(getHour2*1)

			   var totMins = parseInt(getMin*1) + parseInt(getMin2*1);

			   if (totMins <=59)


			   totMins = totMins;




			   totMins = parseFloat(totMins*1);

			   var totMins2 = totMins / 60;



			   var newMin = totMins2.split(".");

			   //var newHour = totMins[0].substring(0, 1)

			   //var newMin2 =  totMins[1].substring(0, 5)













<body onload="calculate();">

<form id="form2" name="form2" action="test.html" method="POST">

<input type='text' name="timeTot" id="timeTot" value="2:45" onBlur="if(timeTot.value!='' && dailyTot.value!='')calculate();">

<input type='text' name="dailyTot" id="dailyTot" value="5:45" onBlur="if(timeTot.value!='' && dailyTot.value!='')calculate();">




Open in new window

Question by:bschave2
    LVL 4

    Expert Comment


    var newMin = totMins2.split(".");

    You should be able to do...

    alert(newMin[0]); //before the dot
    alert(newMin[1]); //after the dot

    Then you can multiply by .06 etc etc


    Author Comment

    I am getting a object doesn't support the property or method error. on the var newMin = totMins2.split("."); code
    LVL 15

    Accepted Solution

    you need to change the decimal number to a string to run the split method...

    var tempTime = totMins2 + "";
    var newMin = tempTime.split(".");
    LVL 82

    Expert Comment

    split is a string method. Try:
    var newMin = String(totMins2).split(".");

    Author Closing Comment

    thanks very much....I am learning javascript as I go.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One JavaScript Help from Top Experts

    Solve your toughest problems, fast.
    JavaScript experts are online now and ready to help you.

    Suggested Solutions

    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now