Convert string to double number

stratus

Active Member
Licensed User
Longtime User
I have this string 56,06 and i want to convert it to double number but i do not know how :sign0104:

PS In Greece we use comma for decimal number.
 

sitajony

Active Member
Licensed User
I use comma too ;)
Why do you want convert a String to Double number?
Maybe you can use it even if it's in String...
You can also use it (I think):
B4X:
txt="56.06"
num=string*1
Else I don't know.. Sorry
 

mjcoon

Well-Known Member
Licensed User
PS In Greece we use comma for decimal number.

Years ago I wrote a freebie program for Psion computers, and some continental (non-UK!) users made the same complaint to me about the numeric punctuation.

The solution was to read this detailed information from the Psion's "locale" data that was set for the device by the user, and modify the program's behaviour accordingly.

In an ideal world that would happen automatically on PPC since the conversion is being done by underlying code. Failing that (as you have discovered) it would be next best to be able to extract the locale information, maybe via the "hardware" library. (But I have not tried to find this out.) Then it would be necessary to do the edit of "," to ".", perhaps using StrReplace().

If there is no locale information available I suppose that you will have to choose to do the edit based on a user's option...

I notice that the Basic4PPC help for the Format() keyword says:
Nn - Number format (dd,ddd,ddd.dddddd) with n digits after the decimal point.

This implies that use of "," versus "." is fixed to the English-speaking convention.

BTW does your device have a calculator application, and if so how does that present decimals?

HTH, Mike.
 

agraham

Expert
Licensed User
Longtime User
Basic4ppc always uses the "en-US" locale for conversions to avoid locale specific problems. Erel has previously told me that he decided to use a fixed locale in Basic4ppc after experiencing locale related problems with numerics in earlier versions. Therefore numeric conversions in Basic4ppc always use the decimal point as the decimal indicator and use commas as the thousands separator where this is required. If your users are likely to enter numeric data with other conventions then as Mike says you will need to check and correct for this.
 

stratus

Active Member
Licensed User
Longtime User
The solution that i found is to trap if a user try to set "," and prompt him to set "." instead ","
 

corwin42

Expert
Licensed User
Longtime User
I'm currently working on my first library for B4PPC which will be called Locale Library. This Library will help to get current culture settings for the device so it would be easy to display calendars, dates and numbers in your device (or any other preferred) language/culture.

I have to fine tune the example program and have a look over the help file again for release. Hope I will have it ready next weekend.
 
Top