DALB Active Member Licensed User Oct 25, 2019 #1 Hello, Finally, I love numbers, but they don't love me ! In this little code: B4X: If s.contains(",") Then s.Replace(",",".") I wish to transform 48,39 to 48.39. So, the answer of the debugger is: java.lang.NumberFormatException: Invalid double: "48,39" But this number would be 48.39 Something is wrong or am I wrong ? Thanks
Hello, Finally, I love numbers, but they don't love me ! In this little code: B4X: If s.contains(",") Then s.Replace(",",".") I wish to transform 48,39 to 48.39. So, the answer of the debugger is: java.lang.NumberFormatException: Invalid double: "48,39" But this number would be 48.39 Something is wrong or am I wrong ? Thanks
DALB Active Member Licensed User Oct 25, 2019 #2 even if I use indexOf, the debugger tells me the same thing !!! Upvote 0
OliverA Expert Licensed User Longtime User Oct 25, 2019 #3 So you’re saying that line of code produces that error message? How? What is s? A string variable? A double? What? Upvote 0
So you’re saying that line of code produces that error message? How? What is s? A string variable? A double? What?
DALB Active Member Licensed User Oct 25, 2019 #4 Thanks for answering OliverA S is here B4X: File.WriteList(File.DirDefaultExternal,fs,lst) lst=File.ReadList(File.DirDefaultExternal , fs) s=lst.Get(0) If s.contains(",") Then s.Replace(",",".") Upvote 0
Thanks for answering OliverA S is here B4X: File.WriteList(File.DirDefaultExternal,fs,lst) lst=File.ReadList(File.DirDefaultExternal , fs) s=lst.Get(0) If s.contains(",") Then s.Replace(",",".")
OliverA Expert Licensed User Longtime User Oct 25, 2019 #5 What did you declare (dim/private/public what?) s as? Upvote 0
DALB Active Member Licensed User Oct 25, 2019 #6 Hooo yes, Xcuse me, s is a string B4X: Dim s As String Upvote 0
OliverA Expert Licensed User Longtime User Oct 25, 2019 #7 What is the output of B4X: File.WriteList(File.DirDefaultExternal,fs,lst) lst=File.ReadList(File.DirDefaultExternal , fs) log($"lst.Get(0): ${lst.Get(0)}"$) s=lst.Get(0) Log($"s: ${s}"$) If s.contains(",") Then s.Replace(",",".") Upvote 0
What is the output of B4X: File.WriteList(File.DirDefaultExternal,fs,lst) lst=File.ReadList(File.DirDefaultExternal , fs) log($"lst.Get(0): ${lst.Get(0)}"$) s=lst.Get(0) Log($"s: ${s}"$) If s.contains(",") Then s.Replace(",",".")
DALB Active Member Licensed User Oct 25, 2019 #8 S takes the value of a latitude , a point on a sphere. I use for instance 48,35° (normaly 48.35°) to calculate a time on a meridian line. Upvote 0
S takes the value of a latitude , a point on a sphere. I use for instance 48,35° (normaly 48.35°) to calculate a time on a meridian line.
OliverA Expert Licensed User Longtime User Oct 25, 2019 #9 That's not what I was asking, and I forgot one more log statement: B4X: File.WriteList(File.DirDefaultExternal,fs,lst) lst=File.ReadList(File.DirDefaultExternal , fs) log($"lst.Get(0): ${lst.Get(0)}"$) s=lst.Get(0) Log($"s: ${s}"$) If s.contains(",") Then s.Replace(",",".") Log($"s: ${s}"$) Upvote 0
That's not what I was asking, and I forgot one more log statement: B4X: File.WriteList(File.DirDefaultExternal,fs,lst) lst=File.ReadList(File.DirDefaultExternal , fs) log($"lst.Get(0): ${lst.Get(0)}"$) s=lst.Get(0) Log($"s: ${s}"$) If s.contains(",") Then s.Replace(",",".") Log($"s: ${s}"$)
DALB Active Member Licensed User Oct 25, 2019 #10 the output remains 48,39 not 48.39 but if I do this code: B4X: Dim s As String="" s=lst.Get(0) Dim i As Int=s.indexOf(",") Dim s1 As String=s.SubString2(0,i) Dim s2 As String=s.SubString2(i+1,s.length) s=s1 & "." & s2 it seems to work. I can add a number without any problem. Upvote 0
the output remains 48,39 not 48.39 but if I do this code: B4X: Dim s As String="" s=lst.Get(0) Dim i As Int=s.indexOf(",") Dim s1 As String=s.SubString2(0,i) Dim s2 As String=s.SubString2(i+1,s.length) s=s1 & "." & s2 it seems to work. I can add a number without any problem.
DALB Active Member Licensed User Oct 25, 2019 #11 can be it due to the phone S5 of Samsung, or from an other origin ? I don't know ! Upvote 0
OliverA Expert Licensed User Longtime User Oct 25, 2019 #12 I'm such a fool/idiot! Strings are immutable!!!! B4X: If s.contains(",") Then s = s.Replace(",",".") End If Upvote 0
I'm such a fool/idiot! Strings are immutable!!!! B4X: If s.contains(",") Then s = s.Replace(",",".") End If
DALB Active Member Licensed User Oct 25, 2019 #13 OliverA What do you mean by immutable ? In some Forums, we can see that strings can be changed with the Replace function ! Upvote 0
OliverA What do you mean by immutable ? In some Forums, we can see that strings can be changed with the Replace function !
M Mahares Expert Licensed User Longtime User Oct 25, 2019 #14 What OliverA means by immutable is that this is wrong in post #10: If s.contains(",") Then s.Replace(",",".") but this is correct in post#12 s = s.Replace(",",".") Upvote 0
What OliverA means by immutable is that this is wrong in post #10: If s.contains(",") Then s.Replace(",",".") but this is correct in post#12 s = s.Replace(",",".")
DALB Active Member Licensed User Oct 25, 2019 #15 Wooo, yes, what a mistake from me ! More than 2 eyes is really usefull ! Thanks to everyone ! Upvote 0