Particle variable show 0.00

I’m using the Particle.variable to display the float of the time as hh.mm. On the console variable section, it displays all times fine but if there’s a 0 at the end it will truncate the display. ie for 21:10 it will display 21.1. Is there a way to set the precision to a fixed amount for the variable function I can do it with publish but not variable

Showing your code would help :wink:

However, that is how floating point variables are typically rendered.
After all 21.1 is the same as 21.100000000 or even pretty much the same as 21.099999999999999999

If you want to display a time with trailing and/or leading zeros you should use a string variable.

1 Like

Sorry about the lack of code!

You’ve managed to help me anyway the string did the trick I didn’t realise you could return strings. I don’t think it’s possible for Particle.function?

I’ve attached my solution if anyone in the future happens to pass by. Sorry for any strange naming I’m self-taught and don’t know the nuances of coding.

Annotation 2020-05-17 122142

Do you know if its possible to declare the the

  Particle.variable("Sunrise Open Time", sunrise2Console);

outside the void setup? I’m trying to reduce my number of global variables. I doubt there is but you seem to know a lot about particle coding!

There is a simpler way to create a formated time string

  Time.format(someTime, "%H:%M");

https://docs.particle.io/reference/device-os/firmware/photon/#format-

Particle.variable() now supports passing in a function instead of a global variable, if that helps.

https://docs.particle.io/reference/device-os/firmware/photon/#particle-variable-calculated

But the actual registration of the variable with the cloud needs to be done in setup() (or at least round about the time the cloud connection gets established).

BTW, you should not use blanks in the Particle.variable name.

What do you mean by blanks?

Should better be

Particle.variable("SunriseOpenTime", sunrise2Console);

according to this
https://docs.particle.io/reference/device-os/firmware/photon/#particle-variable-

Blanks or spaces are used synonymously.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.