• Status: Solved
• Priority: Medium
• Security: Public
• Views: 2016

# how do I split a decimal number?

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<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);
}
else
{
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);
}
else
{
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;
}
else
{
totMins = parseFloat(totMins*1);
var totMins2 = totMins / 60;
totMins2.toString();
}
var newMin = totMins2.split(".");
//var newHour = totMins[0].substring(0, 1)
//var newMin2 =  totMins[1].substring(0, 5)
}
</script>

<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();">
</form>

</body>
</html>
``````
0
bschave2
1 Solution

Commented:
After...

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

You should be able to do...

Then you can multiply by .06 etc etc

0

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

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

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

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

Author Commented:
thanks very much....I am learning javascript as I go.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.