How to convert a double to a string?

  1. last week

    Ivan T

    May 12 Pre-Release Testers
    Edited last week

    This should be straightforward, but...

    Asuming this code:

    Dim aDouble As Double = 3.1415926535897932 ^ 5.5
    Dim aVariant As Variant = aDouble
    
    Dim a As String = aDouble.ToText
    Dim b As String = aVariant.StringValue
    Dim c As String = CStr (aDouble)
    Dim d As String = Str (aDouble)

    How to put the result in a string?

    This is the double value of aDouble (as viewed in debuger and needed in the string)
    542.405768750564107

    a: 542.405769
    b: 5.4240576875056411e+2
    c: 542.4058
    d: 542.4058

    If Xojo can put the value 542.405768750564107 in the debugger window, it should be a way to also get that same value in code isn't it?

    Use FORMAT() and specify the number of digits you want.

  2. Tim H

    May 12 Pre-Release Testers Answer Portland, OR USA

    Use FORMAT() and specify the number of digits you want.

  3. Ivan T

    May 12 Pre-Release Testers

    Well, that was correct, FORMAT did the trick.

    Dim e As String = Format (aDouble, "0.0###############")

    My logic told me that this should be the exact oposite, any convertion should give the exact representation and FORMAT used to have a rounding option with less digits.

  4. Emile S

    May 12 Europe (France, Strasbourg)

    And what said the LR ?

    OK, sometimes I too forgot to read it (or fail to find the data) ;).

or Sign Up to reply!