No announcement yet.

Conversion float to int

  • Filter
  • Time
  • Show
Clear All
new posts

  • Conversion float to int


    I try to use gauge.
    Here is the part of my code, very simple code:

    var volumeValue := 0.4;
    volumeValue *= 100;
    img_SetWord(hndl, iGauge1, IMAGE_INDEX, volumeValue);
    img_Show(hndl, iGauge1);

    This code work when I put directly 40 on the variable volumeValue but when I try to do this conversion, it doesn't work.

    I red the value in volumeValue after the first step and it contain"STA~1.gci".

    Thanks in advance for your answer.

  • #2
    Vars are 16 bit signed integers, so assigning 0.4 to a var will end up with it being assigned 0.

    The compiler produced a warning that tells you this, did you not see it?


    • #3
      Thank you for your answer.

      Yes, indeed the compiler produce a warning but I had not see it. Excuse me for that.

      All your example are with "var XX" so I thought this expression was like "auto XX".

      Can you show me were is the appNote that define all the different expression for the variables ?


      • #4
        If you hit F1 with the cursor over 'func' it will bring up the programmer's reference manual.

        There you will see that variables are always 16 bit signed integers.

        You just need to think withing those restrictions, then everything should be easy.


        • #5
          Thank you again for your answer and your reactivity.

          I have now an other problem with this gauge. I am trying to use it with an external program assuming your serial commander.

          So I can Mount the file on the µSD card and I can load it but The command associate to img_SetWord and img_show doesn't work.

          I think it's because I am not using the right parameters (index or offset).

          for the handle parameter I use the number answered by your equipement when I Load the files.
          for the index I am not sure.. I use the number write in on of the file (11820) convert in hex.
          for the offset I use 9 because of "IMAGE_INDEX"
          and for the value a random value.

          What do you think about it?


          • #6
            Can you use file, zip project and attach your project. Can you also post your Serial Commander log?