Problem with decimals in datafield

I try to get altitude in a datafield, but it gives a lot of decimals. I can't find how to get rid of the decimals


But it rounds, only the altitude but still gives a lot of zeros as decimal.
  • Seems this is a post for the main developer forum.

    But, what are you using to format the values for display?

    Look at using "format"

    it's a function, but the forum seems to not like parens right now!
  • I am a bit frustrated; I couldn't get the code I used in the first post. Some JSON error of the forum software :mad:

    What works is to use the round function, in order to get a 4.0000 instead of a 3.6583. However, it still has those trailing zero's.
    I have tried this: Toybox.Lang.String.format but I don't exactly know how to coplete it (and writing what I have gives a JSON error.....)

    Where can I find the developer-forum?

  • Yeah, the forum hates parentheses. Replace all square brackets with parentheses, below.

    You have two choices:
    - Format the data exactly how you want with format[]
    https://developer.garmin.com/downloa...nstance_method

    e.g. var x = 3.6583;
    x = Math.round[x];
    System.println["x = " + x.Format["%d"]]; // should print "4"


    - The easier way is to just convert the rounded Float to a Number. If you return that in compute() (for a simple data field), it will be printed with no decimals. For a complex datafield, you will be handling the output yourself, naturally.

    e.g.

    function compute[]
    {
    var x = 3.6583;
    x = Math.round[x].toNumber[];
    System.println["x = " + x]; // should print "4"
    return x; // will be displayed as "4"
    }


    You could try the top-level CIQ forum. I think this forum is more for showing off your app when it's ready.
    https://forums.garmin.com/forum/developers/connect-iq
  • Thnx! The conversion from float to number worked fine!