How to display a double as an out of bounds integer string when in Windows

  1. 4 months ago

    Philip C

    Feb 28 Testers, Xojo Pro Cooroy, QLD, Australia
    Edited 4 months ago

    I found that when I compiled for the Mac, integers could be made very large. When I used Int64 and built for windows, it seemed that I was reduced to the integer size for windows, with consequent out of bounds errors.
    I wrote this function to display a double as an integer in text, overcoming this problem

    Function displayDoubleAsInteger(numberToDisplay as Double) As String

    Var myString As String = Floor(numberToDisplay).ToText // number.000000
    Var myIntegerAsInteger=myString.indexof(0,".") // where is the "."
    myString = myString.Left(myInteger) // everything before the "."
    return myString
    End Function

  2. Emile S

    Feb 29 Europe (France, Strasbourg)

    Why don’t you use http://docs.xojo.com/Format ?

  3. Andrew L

    Feb 29 San Francisco, CA, USA

    Integer sizes are the same on Mac and Windows, and integer overflows won't trigger an OutOfBoundsException. I suspect something else was the problem.

  4. Greg O

    Feb 29 Xojo Inc scout.galaxy.barn

    @Philip C I found that when I compiled for the Mac, integers could be made very large. When I used Int64 and built for windows, it seemed that I was reduced to the integer size for windows, with consequent out of bounds errors.
    I wrote this function to display a double as an integer in text, overcoming this problem

    Function displayDoubleAsInteger(numberToDisplay as Double) As String

    Var myString As String = Floor(numberToDisplay).ToText // number.000000
    Var myIntegerAsInteger=myString.indexof(0,".") // where is the "."
    myString = myString.Left(myInteger) // everything before the "."
    return myString
    End Function

    You will however get an out of bounds exception if numberToDisplay starts out with a whole number without a decimal. IndexOf would return -1 and Left(-1) triggers the exception.

  5. Philip C

    Feb 29 Testers, Xojo Pro Cooroy, QLD, Australia

    Thanks for the input everyone. It was a weird error. I thought that integer out of bounds shouldn't occur, but whenever I passed a double to an integer for display purposes, it would give a negative number like an out of bounds error whenever I exceeded 32000 or so.
    I overlooked the Format function - thanks Emile. I am still tracking down the error, but I suspect that using Floor and then converting it to an integer does something weird in Windows but not in OSX

  6. Julian S

    Mar 1 Xojo Pro UK

    What version of xojo and windows are you using?

  7. 2 weeks ago

    Philip C

    Jun 24 Testers, Xojo Pro Cooroy, QLD, Australia

    Xojo 2019 release 3.1 - Mac Cataline, windows 10 under VMWare

  8. Greg O

    Jun 24 Xojo Inc scout.galaxy.barn

    @Philip C Thanks for the input everyone. It was a weird error. I thought that integer out of bounds shouldn't occur, but whenever I passed a double to an integer for display purposes, it would give a negative number like an out of bounds error whenever I exceeded 32000 or so.
    I overlooked the Format function - thanks Emile. I am still tracking down the error, but I suspect that using Floor and then converting it to an integer does something weird in Windows but not in OSX

    You wouldn’t happen to also be using this number for defining the width or height of a picture, would you?

or Sign Up to reply!