add number in string and textbox

Cor

Active Member
Licensed User
Longtime User
Dim totNr,totStr,mynumber As String

totStr="38,8"
Msgbox(totStr,"Foutmelding",cMsgboxOK,cMsgboxHand)
mynumber=edtBoutHoogte.Text ' mynumber ="45,7"
Msgbox(mynumber,"Foutmelding",cMsgboxOK,cMsgboxHand)

' this goes wrong result=-69 instead of -6,9
totNr=totStr-mynumber
Msgbox(totNr,"Foutmelding",cMsgboxOK,cMsgboxHand)

grCor
 

Cor

Active Member
Licensed User
Longtime User
thanks,

distance1 - distance = 38,8 is written into sql as 38,8
distance REAL)

so i read back 38,8

How can I write this value into sql as dot instead as a comma?

I use sql lite

gr
Cor
 

Cor

Active Member
Licensed User
Longtime User
so, the calculation is correct only

when i write it to an sql field which has real as field type

it is written as comma, instead of dot

gr

Cor
 

corwin42

Expert
Licensed User
Longtime User
Here is your example using locale.library to convert the numbers to the correct format. This should work with all languages. num is a locale.library Numeric object.

B4X:
num.New1
Dim totNr,totStr,mynumber As String

totStr="38,8"
Msgbox(totStr,"Foutmelding",cMsgboxOK,cMsgboxHand)
mynumber=textbox1.Text ' mynumber ="45,7"
Msgbox(mynumber,"Foutmelding",cMsgboxOK,cMsgboxHand)

' this goes wrong result=-69 instead of -6,9
totNr=num.Parse(totStr)-num.Parse(mynumber)
Msgbox(totNr,"Foutmelding",cMsgboxOK,cMsgboxHand)

so, the calculation is correct only

when i write it to an sql field which has real as field type

it is written as comma, instead of dot

If it is possible you shouldn't use REAL as data type in sqlite. There is no advantage in doing so as all columns are internally created as strings so use datatype TEXT. The problem with B4PPC is that if you select a number from a REAL column, you will get it in localized form and you have to convert it to the correct form for yourself.
 

Cor

Active Member
Licensed User
Longtime User
thanks

I do now when I read from SQL 4,7

just replace the , with .

s=4,7

s = StrReplace (s,","."")

before doing the calculation

so i don't need the locale lib

grCor
 
Top