Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Question about using floats in Settings

I have a Settings page for my Companion. I'm saving a couple float values. However, it seems like sometimes when I reference the value it comes back as a JSON obj, i.e. {"name":"22.55"} and other times the value appears to come back as a String i.e. "22.55". I can't seem to figure out what causes the difference. Is there a best practice for handling floats from user settings?

Best Answer
0 Votes
4 REPLIES 4

I think I figured what was happening or at least part of it. It seems like when I retrieve a value from settingsStorage.getItem() it returns a JSON object, but when I'm working with events they seem to return the values.

Best Answer
0 Votes

Yes, there's definitely some variations in behaviour.

I think there's a setting property that can make the behaviour a bit more consistent (something like 'usesimplesetting', but I can't find it now).

I suspect that all settings are stored as strings, even if you specify type=float.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I agree that settings are probably stored as strings, however, it seems like when referencing the setting values either the value itself will be returned or an object containing the value will be returned and it seems to be intermittent on which is returned. I'll see if I can find the 'usesimplesetting' property you referred to.

 

thanks

Best Answer
0 Votes

According to Fitbit, there are inconsistencies and different components return different things -- some return the value and some return JSON.  Here is an old thread ,,,

 

https://community.fitbit.com/t5/SDK-Development/SettingsStorage-getItem-from-settings-component/td-p...

 

The way that I compensated for it was to wrap my code in a switch statement based on the key name.  For some key names, return the value.  For others, use JSON.parse to convert it into an object and return the property value.  That way, my function always returns a simple value.

Best Answer