GCM returns numbers as floats

Former Member
Former Member
I noticed the mobile app is returning numbers as floats. This means that if you change a setting you must remember to cast it to the original type before you save it. Maybe this behavior is in the manual? I must admit I haven't looked. Just thought I would mention as a heads-up.
  • IIRC, it is only GCM/Android that does float thing (it's a bug in GCM), but at one time where it returned a string (or maybe that was for booleans...). Since early on with app settings I use something like the following function when reading an integer settings to handle both cases, and something similar for booleans.

    function readKeyInt(myApp,key,thisDefault) {
    var value = myApp.getProperty(key);
    if(value==null || !(value instanceof Number)) {
    if(value!=null) {
    value=value.toNumber();
    } else {
    value=thisDefault;
    }
    }
    return value;
    }


    Here's a post Travis did a while back out some of the other things you might see..

    https://forums.garmin.com/showthread.php?341818-Issue-debugging-settings&p=795298#post795298
  • Former Member
    Former Member over 8 years ago
    Cheers Jim. This reply was just intended as an acknowledgement. Looking at the options though I think I might create my own function. I will simply cast (if required) each value to its intended type when onSettingsChanged() is called.
  • Former Member
    Former Member over 8 years ago
    FWIW here is my spin on it. As mentioned applied in onSettingsChanged()

    function castAsNumber(key) {
    var value = getProperty(key);
    if(!(value instanceof Number)) {
    value = value.toNumber();
    setProperty(key, value);
    }
    return value;
    }