ttsolution Member Licensed User Longtime User Feb 4, 2015 #1 Dear all, I select price from SQLLite as follow query mPrice=Main.SQL1.ExecQuerySingleResult("Select ifnull(PriceWithVAT,0) as PriceWithVAT from ProductPrice Where ItemCode='" & P.ItemCode & "'") result : mPrice= 2.04039E7 (but the actual value is 20403831.8) When I show the value to EditText, it is 2.04039E7 rather than 20403831.8 Many thanks for any help Jonh,
Dear all, I select price from SQLLite as follow query mPrice=Main.SQL1.ExecQuerySingleResult("Select ifnull(PriceWithVAT,0) as PriceWithVAT from ProductPrice Where ItemCode='" & P.ItemCode & "'") result : mPrice= 2.04039E7 (but the actual value is 20403831.8) When I show the value to EditText, it is 2.04039E7 rather than 20403831.8 Many thanks for any help Jonh,
Erel B4X founder Staff member Licensed User Longtime User Feb 4, 2015 #2 ExecQuerySingleResult returns a string. Seems like it loses precision here. Try to use ExecQuery and get the result with Cursor.GetDouble. Upvote 0
ExecQuerySingleResult returns a string. Seems like it loses precision here. Try to use ExecQuery and get the result with Cursor.GetDouble.
ttsolution Member Licensed User Longtime User Feb 4, 2015 #3 I tried with Cursor.GetDouble but same. Thanks Upvote 0
K keirS Well-Known Member Licensed User Longtime User Feb 4, 2015 #4 Use the NumberFormat function to format the number for display in the Editext. Upvote 0
M Mahares Expert Licensed User Longtime User Feb 4, 2015 #5 Another alternative to Erel and keirS good advice is to use the SUBSTR function like this without having to reformat the result: B4X: Dim mPrice As String mPrice=Main.SQL1.ExecQuerySingleResult("Select ifnull(substr(PriceWithVAT,1),0) " _ & "from ProductPrice Where ItemCode='" & P.ItemCode & "'") Log(mPrice) Upvote 0
Another alternative to Erel and keirS good advice is to use the SUBSTR function like this without having to reformat the result: B4X: Dim mPrice As String mPrice=Main.SQL1.ExecQuerySingleResult("Select ifnull(substr(PriceWithVAT,1),0) " _ & "from ProductPrice Where ItemCode='" & P.ItemCode & "'") Log(mPrice)
E edgar_ortiz Active Member Licensed User Longtime User Feb 5, 2015 #6 You can try: mPrice=Main.SQL1.ExecQuerySingleResult("Select cast(ifnull(PriceWithVAT,0) as decimal(10,2)) as PriceWithVAT from ProductPrice Where ItemCode='" & P.ItemCode & "'") Regards Edgar Upvote 0
You can try: mPrice=Main.SQL1.ExecQuerySingleResult("Select cast(ifnull(PriceWithVAT,0) as decimal(10,2)) as PriceWithVAT from ProductPrice Where ItemCode='" & P.ItemCode & "'") Regards Edgar