Converting String to Double

I have a String array. One of the elements = ‘17,1’, NL locale. I want to convert this string to a double: KMDouble = KMArray(8).ToDouble. KMDouble is a Double.

The result = 0. Looking in the debugger I see that the text in the element actually is binary 0031,0037,002C,0031,00, as text ‘.1.7.,.1.’. One way or the other I can’t get rid of the extra characters. How to deal with this?

The encoding of this string looks to be UTF-16 with a trailing null. Try this:

var s as string = KMArray( 8 )

s = s.TrimRight( ChrB( 0 ) ).DefineEncoding( Encodings.UTF16 ).ConvertEncoding( Encodings.UTF8 )

var d as double = s.ToDouble

(Not tested.)

I had difficulties in the string to double conversion in this way too. I finally solved it using this:

KMDouble = Double.FromString(KMArray(8), Locale.Current)

The Binary of the number looks like UTF16BE (Big Endian). Big Endian was used in Classic OS9. Maybe an Encoding is missing at all?

With this code i try to emulate this, getting 0 a well

Var numasstring As String="17,1"

numasstring=numasstring.ConvertEncoding(Encodings.UTF16BE)
numasstring=numasstring.DefineEncoding(Nil)

Var myDouble As Double

myDouble=numasstring.ToDouble

Thanks for all replies. I’ll test and let you know.