How do I round to 2 decimal using Value Display?

Hello folks,

Yes, I searched the forum b4 posting, could not find the answer I am looking for. Here is my question: Using value display, how do I round to two decimal places?

iOS 10
Iphone 7+

Thank you.
Alex

What controller are you using? Arduino?

KevsyBear:

I am using the ESP8266 HUZZAH by AdaFruit, sorry for not specifying that, and thank you for your quick replay.

Not sure but try with:

temperature = round(temperature*100)/100;

Being “temperature” the float you want to round for example.

After that, send this value to the “Value display” using a Virtual Pin

Thank you, psoro, for your reply, I will try that, and update this post later with results.

I think if you use Round() you will not get 2 decimals. Only whole Numbers.
try
temperature = (temperature,2)

If it is just the visual representation you require then:
http://docs.blynk.cc/#widgets-displays-labeled-value

/pin.##/ - displays the value with two decimal places (12.68)

If you actually want to modify a number then it is a combination of float and int with plus 5 for rounding * and / by 100 and 100.0 etc

8 Likes

dennymoney:

This works very well for Serial.print, in my case, I am trying to display values on the Iphone. I have not figured out how to round to 2 decimal .

Costas:

Thank you for your reply, this works for Labeled Value Display, but I cannot figure out how to round to two decimal using Value Display only.

float testfloat = 23.673;
int testint = testfloat * 1000;
testint = testint + 50;  // for rounding
testfloat = testint / 1000.0;

Try something like the above.

2 Likes

I know this is an old post, but just thought I would add what I did to resolve this issue for reference.

sensors.requestTemperatures();
float TankTemp = sensors.getTempCByIndex(0) + CalTemp;
char T[6];
sprintf(T, "%.2f", TankTemp);

this prints to 2 decimal points.