Page 1 of 1

rounding number after calculating celsius?

Posted: Fri Sep 06, 2013 6:56 am
by clearwaterbrewer
I would like to have my custom HMI show one of my temps as F and also as C...

I have the following :

Code: Select all

			var Temp3 = ultemps[ULTMP_TMP + 3]/10;
			var Temp3c = (((Temp3 - 32)*5)/9);
			.
			.
			ctx.fillText(Temp3 + "F " + Temp3c + "C", 200, 132);
and it displays many digits after the decimal point...

I have tried:

Code: Select all

			var Temp3 = ultemps[ULTMP_TMP + 3]/10;
			var Temp3c = round(((Temp3 - 32)*5)/9);
and

Code: Select all

			var Temp3 = ultemps[ULTMP_TMP + 3]/10;
			var Temp3c = math.round(((Temp3 - 32)*5)/9);
and they just don't work... not really sure what I am dealing with...

Re: rounding number after calculating celsius?

Posted: Fri Sep 06, 2013 11:54 pm
by kapavita
i believe you can use the "num.toFixed(no_of_digits)" build in function

var F = 154;
var digs = 1;
var C = (((F - 32)*5)/9).toFixed(digs);

result C=67.8

Re: rounding number after calculating celsius?

Posted: Mon Sep 09, 2013 8:10 am
by clearwaterbrewer
Awesome! .toFixed(digs) worked great! I also used it to make my F displays show the .0

-mike