# Javascript using decimal points in numbers



## gamerman0203 (Oct 28, 2005)

I have a form set up using military time. Hours in one select box and minutes in another. I want to combine them with a decimal point between. Now I know form values are strings so I have to convert values to numbers, but the only way I know how is to use parseInt() and that only grabs the first number and leaves the rest in the dust. Then once they are numbers I want to put them together with a decimal point between them.

any suggestions?


----------



## gamerman0203 (Oct 28, 2005)

ok, silly me! I was using parseInt() which only grabs the first number. I was aware of that. I also though parseFloat() did something with the decimal in the number if it had one. Come to find out I was WAY off! parseFloat() was my answer! 

Here's my code incase someone has something similar they are having problems with:

<script language="javascript">
function calc(){
timeinhours = document.form1.timeinhour.value
timeinmins = document.form1.timeinminute.value
timeouthours = document.form1.timeouthour.value
timeoutmins = document.form1.timeoutminute.value
tti = parseFloat(timeinhours + '.' + timeinmins)
tto = parseFloat(timeouthours + '.' + timeoutmins)

document.form1.totaltime.value = tto - tti
}
</script>

I was tring to use parseInt() and it was coming back with whole numbers and I needed decimal points!


----------

