single or double toText - feedback:37512

Dim singleValue as single = 0.5
Dim outputSingle as Text = singleValue.toText

This outputs a text “0,5000000”

Why is this? And how can I get rid of the zeros so I get 0,5

In the docs I found this:

Dim s As Single = 123.45 Dim t As Text t = s.ToText // t = "123.45"

This is not the case. It outputs : 123.449997

Somethings wrong here.

<https://xojo.com/issue/37512>

[quote=154991:@Christoph De Vocht]Dim singleValue as single = 0.5
Dim outputSingle as Text = singleValue.toText

This outputs a text “0,5000000”

Why is this? And how can I get rid of the zeros so I get 0,5[/quote]

Dim singleValue As Single = 0.5 Dim outputSingle As Text = singleValue.toText(Xojo.Core.Locale.Current)

[quote=154992:@Christoph De Vocht]In the docs I found this:

Dim s As Single = 123.45
Dim t As Text
t = s.ToText // t = “123.45”
This is not the case. It outputs : 123.449997

Somethings wrong here.[/quote]
Which is correct, since 123,45 is not storable in a Single (or Double).

Dim s As Single = 123.45 Dim t As Text t = s.ToText(Xojo.Core.Locale.Current) // t = "123.45"

That makes sense. But the example in the docs did put me on the wrong track.

I knew I had seen a format parameter in ToText. That is for Double :
http://xojo.helpdocsonline.com/double

So essentially, you would have to use a double to perform the ToText and you can have any format you want, as with Format in the previous framework :

dim s as single = 1.2345678 dim d as double = s dim t as Text t = d.ToText(Locale.Current, "#,###.##")