Click to See Complete Forum and Search --> : round up decimal points on temp converter?


helsinkihammer
10-28-2003, 09:09 AM
This code converts from Fahrenheit to Celcius and works fine, but I'd like it to rounding up the answer to the nearest whole number. Any suggestions?

<script language="JavaScript">
<!-- hide this script from old browsers
function temp(form)
{
var f = parseFloat(form.DegF.value, 10);
var c = 0;
c = (f - 32.0) * 5.0 / 9.0;
form.DegC.value = c;
}
// done hiding from old browsers -->
</script>

The degree celcius value = c

Many thanks in advance to you generous people :)
Mark

helsinkihammer
10-28-2003, 09:17 AM
:rolleyes: :rolleyes: :rolleyes:

Well, I should have read the sticky first, because after doing a search, I found the answer already on another post.

I added the line to the code:

c*=1; c=Math.round(c); c/=1;

Where c is the value for Celcius, and this now rounds up the celcius value to a whole number.

Helsinki Hammer