Too many decimal places on display widget

I’m sending floating point values to display widgets on my dashboard and getting more decimal places than I would like. Is there a way to only get one decimal place displayed?

For example, if I have a floating point value of 1.234 I would like it to display as 1.2.

We have something like this for temperature from 2 to 1 decimal place:

float temp = 20.25;
int newtemp = ((temp + 0.05) * 10);
temp = (newtemp / 10.0);
Blynk.virtualWrite(V10, temp);   // shows 20.3 on Value Display rather than the original 20.25

Thanks so much for the help @Costas. That looks like what I’m after. I haven’t tried it yet but I see the logic. Cheers

thanks Costas, i learn from nearly all your posts :slightly_smiling:

@NickMurray - which enviro. sensors are you using?

Cheap eBay ones. Haha. DHT11 for humidity and temperature. BMP180 also for temperature and pressure and some generic no name LDR for light.

Lol, obviously accuracy is not number 1 priority then? (no offence)

More “just for interests sake”, still nice to have!

I’m running BME280’s and matched set of DHT22’s in my ventilation controller, and even these are a few percent tolerance… But i don’t think spending 25 bucks a sensor is gonna get me a better result than these 5 dollar ones…

Is your power monitor anything interesting? I’ve got Efergy on our meter box, but wondering if I could hack it’s WiFi signal via esp8266?

Hi Dave,
I would like good accuracy eventually but I guess I’m just in the experimental stage at the moment. I’ll look into the sensors you have suggested.

The power monitor is a bit of a ‘loose’ term for what I have. I just measure the current using a very inexpensive SCT13 split core CT, again from eBay. Use the current value from the sensor, then use a calculation in the Arduino sketch with nominal values of voltage and power factor.

The split core CT just clips onto my mains cable so no messing with the house wiring. It is freakishly accurate when compared to a good quality fluke clamp on amp meter that I have.

Thanks again for the help. I still needed to manipulate the string a bit more to trim off the last character but I have the result I was after. Cheers

this method works only for Android.
IOS keeps displaying numbers the same old way :frowning2:
Android also drops zeros in 2 decimal point values, even in Labeled Value Displays where it is specified to display 2 decimal points /pin.##/
Any ideas how to fix this? 1 decimal point will be enough.

@iGonch I have no idea why iOS does not respond to the float to int rounding and back to float fix.
Are you saying losing the zeros is ok for you in Android or you need to see so many zeros? If so how many zero do you require? It’s probably done by multiplying by 100 / 1000 and adding 50 / 500 for rounding etc.

Thanks, Costas!
Well… IOS insists on 3 decimal points in Value display widgets, regardless of my efforts(
Is there a way to convert this variable to character, then specify its length in code, and then send it to widget?

Hi iGonch,
I use this kind of code:

dtostrf(Voltage, 1, 2, Buffer);
Blynk.virtualWrite(V2, Buffer);

where, in this example, Voltage is a float number that must be printed with only 2 decimal points and Buffer is an array of char:

float Voltage;
char Buffer[16];

The “1” in dtostrf function is the width. You can leave this value.
The “2” is the precision. This is the value to tune for your case.
V2 is the virtual pin used in this example.

For reference, you can look at:



@iGonch Hi Andrey, does it work for you ?

1 Like

It HAS to work (for him, and everyone else) as this way the value is send as a formatted string! And the dtostrf is the only function (or am I wrong?) supported on Arduino ide to do it. Unfortunately printf() does not work with floats by default in Arduino IDE. I’m using dtostrf() too, though would prefer printf()

1 Like

yes! it works perfectly! thanks a lot!

@marvin7 Me too prefer sprintf() function but I confirm that it doesn’t work with floats (a question mark is printed). The problem is not Arduino IDE but AVR lib that disable it for floats in order to save microcontroller memory.

Yes, I know its the AVR, it’s just a kind of (bit misleading) shortcut :blush: (As if another IDE would allow for that by default? NO WAY!). I also know, that there is a way to enable it, but as long as there is ANOTHER way to do it, i don’t bother (and have no time too)
But perhaps boys from ArduinoIDE for ESP would do it? I’m not sure, but just thinking: Should be possible to integrate some tweaks for more capable ESP chip(s)