Convert Integer to Double

  1. 2 weeks ago

    Ralph A

    Oct 11 Santa Monica, California

    I've been using the following to convert an Integer to a Double:

    Val(Str(i))

    where i is an Integer.

    Is there a more direct way to do this? I need to convert an Integer occasionally to a Double to use Format.

    Format accepts either a Double or an Integer. No conversion required.

    Any function that accepts a Double will also accept an Integer.

    In general, Integer converts automatically to Double. That makes it hard to distinguish the two, but makes it easy to code.

  2. Jean-Yves P

    Oct 11 Pre-Release Testers, Xojo Pro Europe (France, Besancon)
    dim i as integer  = 5
    dim d as double = i
    msgbox str(d)
  3. Deleted 2 weeks ago by Eli O
  4. Tim H

    Oct 12 Pre-Release Testers Answer Portland, OR USA
    Edited 2 weeks ago by Tim H

    Format accepts either a Double or an Integer. No conversion required.

    Any function that accepts a Double will also accept an Integer.

    In general, Integer converts automatically to Double. That makes it hard to distinguish the two, but makes it easy to code.

  5. Ralph A

    Oct 12 Santa Monica, California

    @Tim H Format accepts either a Double or an Integer. No conversion required.

    Any function that accepts a Double will also accept an Integer.

    In general, Integer converts automatically to Double. That makes it hard to distinguish the two, but makes it easy to code.

    Well, well. I thought I always found the compiler complaining about using an Integer in the Format function, but now I see it's fine with it. Not sure what I was doing in the past that made me think that. Thanks as usual, Tim.

or Sign Up to reply!