rounding number after calculating celsius?

Using the HMI Builder and creating custom interfaces for the BCS.
Post Reply
clearwaterbrewer
Posts: 383
Joined: Wed Feb 09, 2011 3:43 pm
Bot?: No
Location: Clearwater, FL
Contact:

rounding number after calculating celsius?

Post 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...
kapavita
Posts: 20
Joined: Tue Feb 09, 2010 11:22 am
Bot?: No
Location: Palo Alto, CA

Re: rounding number after calculating celsius?

Post 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
clearwaterbrewer
Posts: 383
Joined: Wed Feb 09, 2011 3:43 pm
Bot?: No
Location: Clearwater, FL
Contact:

Re: rounding number after calculating celsius?

Post by clearwaterbrewer »

Awesome! .toFixed(digs) worked great! I also used it to make my F displays show the .0

-mike
Post Reply