photoxprt1868
Programmer
Hello,
I found this function here to always have two decimal places after rounding but how can I apply it to a form value
this is the function
and this is where I need to apply it
or when I actually calculate it in the head
Thank you very much for your help
I found this function here to always have two decimal places after rounding but how can I apply it to a form value
this is the function
Code:
<script language="javascript">
<!--
function numberFormat(str)
{
if(str.indexOf(".") == -1)
{
return str;
}
splitString = str.split(".");
var newSplitString = splitString[1];
for(i=0; i < (2 - splitString[1].length); i++)
{
newSplitString = newSplitString + "0";
}
return (splitString[0] + "." + newSplitString);
}
document.write(numberFormat('2.1'))
-->
</script>
and this is where I need to apply it
Code:
document.compareForm.charge2005.value = "$ " + cost2005;
or when I actually calculate it in the head
Code:
var fuel2006 = Math.round(((fuel1st1000kwh * first1000) + (fuelOver1000kwh * over1000))*100)/100;
Thank you very much for your help