Double to text format

Converting text to double and vice-versa gives bizarres results.

OpenWindowEvent: aValue = 123.456 // aValue is a double

Button GetValue
Sub Action() Handles Action
TextField1.Text = aValue.ToText
TextField3.Text = Format(aValue, “#.##”)
End Sub

Button PassValue
Sub Action() Handles Action
var d as Double = TextField1.Text.ToDouble
d = d + 1
TextField2.Text = d.ToString
TextField4.Text = Format(d, “#.##”)
End Sub

Am I doing wrong? Or is a malfunction?

I get the correct results

Textfield1: 123.456000
Textfield2: 124.456000
Textfield3: 123.46
Textfield4: 124.46

in Windows, Xojo 2020r2.1 on a USA system. From your image, it looks like you are not on an English-based system so the problem might be unique to whatever your system’s language is.

I would suggest stepping through the code in the debugger to see exactly which statement converts incorrectly.

see also

This works, but like @Dale_Arends I’m on an English (decimal) system…

Var myStr as String = "123.456"
Var myDbl as Double
myDbl = myStr.ToDouble
System.DebugLog(myDbl.ToString) // 123.456000
myDbl = myDbl + 1
System.DebugLog(Format(myDbl, "#.##")) // 124.46

The problem you see I raised an issue with back in 2016 but it was marked as a feature request and not a bug…


Formatting is extremely broken, please add your test cases/example projects to this ticket:


Var myDbl as Double = 123.456
Var myStr as String =myDbl.ToString

System.DebugLog(myStr) // 123.456000

myDbl = myStr.ToDouble
myDbl = myDbl +1

myStr  =myDbl.ToString
System.DebugLog(myStr) // 123456001.000000