dobbies
10-07-2012, 02:11 PM
I am using this code to convert liquid volume but it converts too many decimal places. Could someone show me how to reduce the conversion to 1 or 2 decimal places?
Many thanks
// JavaScript Document
<!--
function nofocus()
{
document.convert.InUnit.focus()
}
var mlValue = 1
var ltrValue = 1000
var fozValue = 28.4
var cupValue = 236
var ptValue = 568.261
function toCM()
{
var i = document.convert.unit.selectedIndex
var thisUnit = document.convert.unit.options[i].value
if (thisUnit == "ML")
{
document.convert.ml.value = document.convert.InUnit.value
}
else if(thisUnit == "LTR")
{
document.convert.ml.value = document.convert.InUnit.value * ltrValue
}
else if(thisUnit == "FOZ" )
{
document.convert.ml.value = document.convert.InUnit.value * fozValue
}
else if(thisUnit == "CUP" )
{
document.convert.ml.value = document.convert.InUnit.value * cupValue
}
else if(thisUnit == "PT" )
{
document.convert.ml.value = document.convert.InUnit.value * ptValue
}
toAll()
}
function toAll()
{
var m = document.convert.ml.value
document.convert.ltr.value = m / ltrValue
document.convert.foz.value = m / fozValue
document.convert.pt.value = m / ptValue
document.convert.cup.value = m / cupValue
}
//-->
Many thanks
// JavaScript Document
<!--
function nofocus()
{
document.convert.InUnit.focus()
}
var mlValue = 1
var ltrValue = 1000
var fozValue = 28.4
var cupValue = 236
var ptValue = 568.261
function toCM()
{
var i = document.convert.unit.selectedIndex
var thisUnit = document.convert.unit.options[i].value
if (thisUnit == "ML")
{
document.convert.ml.value = document.convert.InUnit.value
}
else if(thisUnit == "LTR")
{
document.convert.ml.value = document.convert.InUnit.value * ltrValue
}
else if(thisUnit == "FOZ" )
{
document.convert.ml.value = document.convert.InUnit.value * fozValue
}
else if(thisUnit == "CUP" )
{
document.convert.ml.value = document.convert.InUnit.value * cupValue
}
else if(thisUnit == "PT" )
{
document.convert.ml.value = document.convert.InUnit.value * ptValue
}
toAll()
}
function toAll()
{
var m = document.convert.ml.value
document.convert.ltr.value = m / ltrValue
document.convert.foz.value = m / fozValue
document.convert.pt.value = m / ptValue
document.convert.cup.value = m / cupValue
}
//-->