S sorex Expert Licensed User Longtime User Aug 15, 2019 #1 Hello, It seems that the "no formatting" method is being overruled when math is being applied in the advanced strings method. I noticed it when removing recalculated grid coordinates from a map didn't seem to work. Code: Copy Log($"d0=${data2(0)} - d1:${data2(1)} - sy:${sy} - sx=${sx} dy=${data2(0)-sy} - dx:${data2(1)-sx}"$) Log($"d0=$1.0{data2(0)} - d1:$1.0{data2(1)} - sy:$1.0{sy} - sx=$1.0{sx} dy=$1.0{data2(0)-sy} - dx:$1.0{data2(1)-sx}"$) log: d0=4 - d1:4 - sy:4 - sx=4 dy=0.0 - dx:0.0 d0=4 - d1:4 - sy:4 - sx=4 dy=0 - dx:0 notice the 0.0 on the substracted values
Hello, It seems that the "no formatting" method is being overruled when math is being applied in the advanced strings method. I noticed it when removing recalculated grid coordinates from a map didn't seem to work. Code: Copy Log($"d0=${data2(0)} - d1:${data2(1)} - sy:${sy} - sx=${sx} dy=${data2(0)-sy} - dx:${data2(1)-sx}"$) Log($"d0=$1.0{data2(0)} - d1:$1.0{data2(1)} - sy:$1.0{sy} - sx=$1.0{sx} dy=$1.0{data2(0)-sy} - dx:$1.0{data2(1)-sx}"$) log: d0=4 - d1:4 - sy:4 - sx=4 dy=0.0 - dx:0.0 d0=4 - d1:4 - sy:4 - sx=4 dy=0 - dx:0 notice the 0.0 on the substracted values
Erel B4X founder Staff member Licensed User Longtime User Aug 15, 2019 #2 I don't see any bug here. If you don't specify the number of fraction points like you did on the second line then the format cannot be assumed. You should never convert numbers to string without using specifically formatting the number with NumberFormat, $x.y or B4XFormatter. Upvote 0
I don't see any bug here. If you don't specify the number of fraction points like you did on the second line then the format cannot be assumed. You should never convert numbers to string without using specifically formatting the number with NumberFormat, $x.y or B4XFormatter.
S sorex Expert Licensed User Longtime User Aug 15, 2019 #3 the numbers are plain INTs. there's no need to add .0 to it as I didn't pick $1.1{} so the assumed format is just 1.0 as I use ${} (no formatting). Upvote 0
the numbers are plain INTs. there's no need to add .0 to it as I didn't pick $1.1{} so the assumed format is just 1.0 as I use ${} (no formatting).
S sorex Expert Licensed User Longtime User Aug 15, 2019 #4 see it as abs(0-1) would still give -1. the outer command is ignored (not removing the 0.0 formatting) Upvote 0
see it as abs(0-1) would still give -1. the outer command is ignored (not removing the 0.0 formatting)
Erel B4X founder Staff member Licensed User Longtime User Aug 15, 2019 #5 You should never convert numbers to string without specifically formatting the number with NumberFormat, $x.y{} or B4XFormatter. Don't assume the default format. It can change based on all kinds of parameters. Upvote 0
You should never convert numbers to string without specifically formatting the number with NumberFormat, $x.y{} or B4XFormatter. Don't assume the default format. It can change based on all kinds of parameters.
S sorex Expert Licensed User Longtime User Aug 15, 2019 #6 sorry but I don't see the relevance as the ${} no format happends last in the "operation" I select no formatting and there is formatting applied. it should only be there when it is for example 0.5 no formatting means to me removing formatting if there is any on INTs and not adding some unwanted one. Upvote 0
sorry but I don't see the relevance as the ${} no format happends last in the "operation" I select no formatting and there is formatting applied. it should only be there when it is for example 0.5 no formatting means to me removing formatting if there is any on INTs and not adding some unwanted one.
Erel B4X founder Staff member Licensed User Longtime User Aug 16, 2019 #7 BTW, the output of this code is 0 not 0.0: Code: Copy Dim sx, sy As Int Dim data2(10) As Int Log($"d0=${data2(0)} - d1:${data2(1)} - sy:${sy} - sx=${sx} dy=${data2(0)-sy} - dx:${data2(1)-sx}"$) Still it is a programming mistake to omit the formatting specification as the default formatting might not be what you expect. It is also very simple to do. Upvote 0
BTW, the output of this code is 0 not 0.0: Code: Copy Dim sx, sy As Int Dim data2(10) As Int Log($"d0=${data2(0)} - d1:${data2(1)} - sy:${sy} - sx=${sx} dy=${data2(0)-sy} - dx:${data2(1)-sx}"$) Still it is a programming mistake to omit the formatting specification as the default formatting might not be what you expect. It is also very simple to do.
S sorex Expert Licensed User Longtime User Aug 16, 2019 #8 data2() is strings because data comes from a regex.split that there are differences between the old fashioned method and the advanced one can be seen with this code and only the ${} method adds formatting. putting the blame on a coding mistake would make the old fashioned method format wrong aswell but it doesn't as it covers something that is missing in ${}. both method should output the same thing that's what I'm trying to say. Code: Copy Dim v1 As String=2 Dim v2 As Int=1 Log(v1-v2) Log("v:"& (v1-v2)) Log($"v:${v1-v2}"$) Waiting for debugger to connect... Program started. 1 v:1 v:1.0 Upvote 0
data2() is strings because data comes from a regex.split that there are differences between the old fashioned method and the advanced one can be seen with this code and only the ${} method adds formatting. putting the blame on a coding mistake would make the old fashioned method format wrong aswell but it doesn't as it covers something that is missing in ${}. both method should output the same thing that's what I'm trying to say. Code: Copy Dim v1 As String=2 Dim v2 As Int=1 Log(v1-v2) Log("v:"& (v1-v2)) Log($"v:${v1-v2}"$) Waiting for debugger to connect... Program started. 1 v:1 v:1.0
Erel B4X founder Staff member Licensed User Longtime User Aug 16, 2019 #9 Moved to the questions forum. sorex said: data2() is strings because data comes from a regex.split Click to expand... When a string is parsed to a number it can be converted to a double. You shouldn't assume that it will be converted to an int just because the number is a whole number. Bottom line, which was written 5 times already, use the format specifier. It is very simple. Upvote 0
Moved to the questions forum. sorex said: data2() is strings because data comes from a regex.split Click to expand... When a string is parsed to a number it can be converted to a double. You shouldn't assume that it will be converted to an int just because the number is a whole number. Bottom line, which was written 5 times already, use the format specifier. It is very simple.