Type conversion Simulator vs Watch

May be it would be helpfull for someone:

I have a code:
for ( var i = 1; i <= 30; i += 1 ) {
...
dc.drawText(x, y, Gfx.FONT_XTINY, i, Gfx.TEXT_JUSTIFY_RIGHT);
...

it works Ok on Connect IQ Device Simulator but not on watch (Fenix 3): "IQ" icon with exclamation mark displayed when app (widget) starts.

but it works on both simulatore and watch rewritten:
...
dc.drawText(x, y, Gfx.FONT_XTINY, " " + i, Gfx.TEXT_JUSTIFY_RIGHT);
...

i.e. with implicit type conversion
  • May be it would be helpfull for someone:

    I have a code:
    for ( var i = 1; i <= 30; i += 1 ) {
    ...
    dc.drawText(x, y, Gfx.FONT_XTINY, i, Gfx.TEXT_JUSTIFY_RIGHT);
    ...

    it works Ok on Connect IQ Device Simulator but not on watch (Fenix 3): "IQ" icon with exclamation mark displayed when app (widget) starts.

    but it works on both simulatore and watch rewritten:
    ...
    dc.drawText(x, y, Gfx.FONT_XTINY, " " + i, Gfx.TEXT_JUSTIFY_RIGHT);
    ...

    i.e. with implicit type conversion

    That's good to know. Thanks!
  • This is a trick I often use (saves having the toString() or format() in the code.)

    I often use it if there is a label for the number, such as:

    dc.drawText(x,y,Gfx.FONT_SMALL,"Count: "+i,Gfx.TEXT_CENTER);

    The leading sting can also be empty: ""+i

    That way it doesn't impact the justification.
  • This applies to integer vs float conversions too. Some things the simulator will automatically convert to float for you even if you forgot to, but the actual watch will leave as integer.
  • ...but if you just add .toString() after i ?


    That's good to know. Thanks!