makis_best Well-Known Member Licensed User Longtime User Dec 10, 2019 #1 Hi. I have a table with 4 columns Quantity, Price, Total and add to order. When I add quantity and Price in column total I see the result For example if I put in quantity 100 and in price 11.4307 then I get total as 1,143.07. After that I press the Add to order button witch read the total column my program stop working and I get one error message saying about invalid double. ** Activity (esfiitems) Create, isFirst = true ** ** Activity (esfiitems) Resume ** Error occurred on line: 969 (Table) java.lang.NumberFormatException: Invalid double: "1,143.07" at java.lang.StringToReal.invalidReal(StringToReal.java:63) at java.lang.StringToReal.initialParse(StringToReal.java:164) at java.lang.StringToReal.parseDouble(StringToReal.java:282) at java.lang.Double.parseDouble(Double.java:301) at gr.iosif.droidview.esfiitems$ResumableSub_ItemTable_All_Items_CellClick.resume(esfiitems.java:2445) at gr.iosif.droidview.esfiitems._itemtable_all_items_cellclick(esfiitems.java:1884) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144) at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1083) at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:1046) at gr.iosif.droidview.table._cell_click(table.java:1568) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144) at anywheresoftware.b4a.BA.raiseEvent(BA.java:176) at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80) at android.view.View.performClick(View.java:4764) at android.view.View$PerformClick.run(View.java:19844) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5376) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908) Click to expand... Why that happens? It is about decimal format? I use Table CustomView Version 3.02 and Android 8 with B4A 9.50 Thank you
Hi. I have a table with 4 columns Quantity, Price, Total and add to order. When I add quantity and Price in column total I see the result For example if I put in quantity 100 and in price 11.4307 then I get total as 1,143.07. After that I press the Add to order button witch read the total column my program stop working and I get one error message saying about invalid double. ** Activity (esfiitems) Create, isFirst = true ** ** Activity (esfiitems) Resume ** Error occurred on line: 969 (Table) java.lang.NumberFormatException: Invalid double: "1,143.07" at java.lang.StringToReal.invalidReal(StringToReal.java:63) at java.lang.StringToReal.initialParse(StringToReal.java:164) at java.lang.StringToReal.parseDouble(StringToReal.java:282) at java.lang.Double.parseDouble(Double.java:301) at gr.iosif.droidview.esfiitems$ResumableSub_ItemTable_All_Items_CellClick.resume(esfiitems.java:2445) at gr.iosif.droidview.esfiitems._itemtable_all_items_cellclick(esfiitems.java:1884) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144) at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1083) at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:1046) at gr.iosif.droidview.table._cell_click(table.java:1568) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144) at anywheresoftware.b4a.BA.raiseEvent(BA.java:176) at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80) at android.view.View.performClick(View.java:4764) at android.view.View$PerformClick.run(View.java:19844) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5376) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908) Click to expand... Why that happens? It is about decimal format? I use Table CustomView Version 3.02 and Android 8 with B4A 9.50 Thank you
Erel B4X founder Staff member Licensed User Longtime User Dec 10, 2019 #2 It is a mistake to use the value of the formatted string instead of the real value behind it. If you don't have access to the real value then remove the thousands separator: Code: Dim d As Double = Text.Replace(",", "") Upvote 0
It is a mistake to use the value of the formatted string instead of the real value behind it. If you don't have access to the real value then remove the thousands separator: Code: Dim d As Double = Text.Replace(",", "")
makis_best Well-Known Member Licensed User Longtime User Dec 10, 2019 #3 I understand what you say @Erel but there is no way just to change all the number format all over the application? Upvote 0
I understand what you say @Erel but there is no way just to change all the number format all over the application?
Erel B4X founder Staff member Licensed User Longtime User Dec 10, 2019 #4 Formatting numbers is usually explicitly done with NumberFormat(2) keyword. You cannot disable this keyword. I will repeat that it is a mistake to do anything with the formatted text except of displaying it to the user. You should use the actual values to avoid accumulated precision errors. Upvote 0
Formatting numbers is usually explicitly done with NumberFormat(2) keyword. You cannot disable this keyword. I will repeat that it is a mistake to do anything with the formatted text except of displaying it to the user. You should use the actual values to avoid accumulated precision errors.
klaus Expert Licensed User Longtime User Dec 10, 2019 #5 How do you fill the Table? It seems that you format the display somewhere with NumberFormat2, you shouldn't. There is no NumberFormat nor NumberFormat2 method used in the Table class. Upvote 0
How do you fill the Table? It seems that you format the display somewhere with NumberFormat2, you shouldn't. There is no NumberFormat nor NumberFormat2 method used in the Table class.
makis_best Well-Known Member Licensed User Longtime User Dec 10, 2019 #6 The code I use to fill the cell Code: ItemTable_All_Items.SetValue(5, row, NumberFormat(Quantity1 * ItemTable_All_Items.GetValue(3, row), 0, 4)) I just want to have 4 digits after decimal. Last edited: Dec 10, 2019 Upvote 0
The code I use to fill the cell Code: ItemTable_All_Items.SetValue(5, row, NumberFormat(Quantity1 * ItemTable_All_Items.GetValue(3, row), 0, 4)) I just want to have 4 digits after decimal.
Erel B4X founder Staff member Licensed User Longtime User Dec 10, 2019 #7 You can use NumberFormat2 and set the GroupingUsed parameter to False. Upvote 0
klaus Expert Licensed User Longtime User Dec 10, 2019 #8 Do you want to reuse these values to calculate something else? If yes, be aware that you may loose on accuracy by formatting the values. Upvote 0
Do you want to reuse these values to calculate something else? If yes, be aware that you may loose on accuracy by formatting the values.
makis_best Well-Known Member Licensed User Longtime User Dec 10, 2019 #9 @klaus I use the value to calculate something else. That's why I want 4 decimal digits. Upvote 0
makis_best Well-Known Member Licensed User Longtime User Dec 10, 2019 #10 Numberformat2 did the trick. Upvote 0
klaus Expert Licensed User Longtime User Dec 10, 2019 #11 I use the value to calculate something else. Click to expand... In that case you should memorize the value(s) somewhere else as a Double. Upvote 0
I use the value to calculate something else. Click to expand... In that case you should memorize the value(s) somewhere else as a Double.
advansis Active Member Licensed User Longtime User Dec 15, 2019 #12 What about storing the real value used for calculation (multiplied by 10000 and rounded) in an hidden column? Upvote 0
What about storing the real value used for calculation (multiplied by 10000 and rounded) in an hidden column?