Some integer values may be regarded as float in Enduro 3

One of my users reported me that the value originated from Weather.getCurrentConditions().precipitationChance is shown as float value, which means shown like 23.3333333....

Values converted by toNumber seems to have same issue.

It works well for my device Vivoactive 4.

Does anyone have idea?

  • Not the first time they change an API without notice or even changing the documentation. Looks like this should be now Number OR Float OR null

  • Thank you for immediate reaction!

    Oh, I didn’t know that… It seems that there is another issue about toNumber() conversion but anyway it might be good to try format(%d) or something like that…

    Thanks again!

  • I guess toNumber should be OK, just check before that it's not null

  • Great insight!

    It totally makes sense that null does something wrong! I will add a null check before using the value.

    Thanks again!

  • You want to null check everything you use from currentConditions  in this case, if you tried to do a toNumber() on a null value, the app should have crashed and you'd see that in ERA

    Recently things like temperatures will be a Float and not a Number on newer devices, but if you do a conversion from C to F, even if C is a Number, the result should be a Float, so you just handle both the same way.

    Another change is that observationLocationName is now null on real devices.

  • Thank you for your comment!

    I’ve checked my source and found that some values in getDailyForecast also have changed from integer to float…

    Originally I thought the issue occurs for getCurrentCondition, which I converted the value to integer. However, I didn’t convert the value in getDailyForecast and the user might report the issue about getDailyForecast…

    Anyway, I think this thread can be closed. Thank you again!

  • some values in getDailyForecast also have changed from integer to float…

    To be clear their types in the SDK changed from Number (integer) to Numeric (Long/Number/Double/Float). Some devices return integers for these values and some devices return floating point numbers, but, for some time, the SDK type information incorrectly stated that their type was (only) Number.

  • but if you do a conversion from C to F, even if C is a Number, the result should be a Float, so you just handle both the same way.

    But once again, typically, devs also have to handle the case where a conversion from Celsius to Fahrenheit is *not* done, unless exactly 0 of their users prefer Celsius.

    (Hint: not everyone lives in America)

    I'm loath to bring this up, but I'll also point out that calling toNumber() on a Float (or Double) will simply truncate it (throw away the decimal portion), while the desired behavior may be to round to the nearest integer (using Math.round(). (I am not making any claims about which strategy is better for OP, just saying that it may be a consideration.)