printing doubles

I am troubleshooting an app which uses doubles and am therefore trying to print them using System.println(). But when I do this nothing appears. If I convert to float, i.e. System.println(d.toFloat()) this works fine, but I loose the precision and this is what I am trying to troubleshoot.

Is a bug? Should println() be able to print doubles? Is there any way to do this?
  • Former Member
    Former Member over 9 years ago
    Read the Api documentation

    Hi i recomend to read the documentation, you have to define that the var atribute is a float, only in that case the value is going to show decimal.
    http://developer.garmin.com/connect-iq/developer-tools/functions/

    var n = null; // Null reference
    var x = 5; // 32 bit signed integers
    var y = 6.0; // 32 bit floating point
    var l = 5l; // 64 bit signed integers
    var d = 4.0d; // 64 bit floating point
    var bool = true; // Boolean (true or false)
    var arr = new [20 + 30]; // Array of size 50
    var str = "Hello"; // String var dict = { x=>y }; // Dictionary: key is 5, value is 6.0
    var z = arr[2] + x; // Null pointer waiting to happen


    to show decimals format:

    var a = value/10.0
    you have tell to the atribute that the result is an float, in this case addind the .0

    print(a.format("%.2f))http://developer.garmin.com/connect-iq/developer-tools/functions/
  • I have read the documentation, I think you miss the point.

    The problem was that System.println() will print floating point variables natively but will not print doubles natively:

    var f = 0.123456789;
    var d = 0.123456789d;
    System.println(f);
    System.println(d);

    shows only:

    0.123457

    i.e. only the floating point number was printed, the double was not. But I did find that if you use format you can get it to print by converting to a string before printing:

    var f = 0.123456789;
    var d = 0.123456789d;
    System.println(f.format("%.9f"));
    System.println(d.format("%.9f"));

    which shows:

    0.123456791
    0.123456789

    So this does beg the question, why can println() print floats but not doubles. Although I have a solution to my problem.
  • Former Member
    Former Member over 9 years ago
    This looks like a bug to me, I'll create a ticket to investigate.
  • We were able to reproduce this in the 1.1.4 SDK on Windows only, but it's not an issue in 1.2.0. For now, you'll need to use the format-as-float fix, but that won't be necessary once 1.2.0 is released.