Lori
(Li)
January 11, 2024, 6:51am
1
Description:
I have one excel with some data
I add one data row
I use DT_Test.AsEnumerable().Sum(Function(row) row.Field(Of Double)(“Total”))
I can not get right sum value ,it give me wrong data (4.54747350886464E-12), in fact, the sum result should be zero
could you anyone help me ,thanks.
BlankProcess_Test20240111.zip (46.0 KB)
I attachment my process for your reference, thanks.
vrdabberu
(Varunraj Dabberu)
January 11, 2024, 6:54am
2
Hi @Lori
YourDataTable.AsEnumerable().Sum(Function(x) If(Not String.IsNullOrEmpty(x("Column Name").ToString()) or Not String.IsNullOrWhiteSpace(x("Column Name").ToString()), Convert.ToDecimal(x("Column Name")), 0)).ToString()
Regards
rlgandu
(Rajyalakshmi Gandu)
January 11, 2024, 6:55am
3
@Lori
DT_Test.AsEnumerable().Sum(Function(row) Math.Round(row.Field(Of Double)(“Total”), 2))
Math.Round(row.Field(Of Double)("Total"), 2)
rounds each value in the “Total” column to 2 decimal places before summing them up. Adjust the number of decimal places according to your precision requirements.
vrdabberu
(Varunraj Dabberu)
January 11, 2024, 6:57am
4
Hi @Lori
YourDataTable.AsEnumerable().Sum(Function(x) If(Not String.IsNullOrEmpty(x("Total").ToString()) or Not String.IsNullOrWhiteSpace(x("Total").ToString()), Convert.ToDecimal(x("Total")), 0)).ToString()
Replace the YourDataTable with the actual DataTable Variable.
Regards
Yoichi
(Yoichi)
January 11, 2024, 7:00am
5
Hi,
Can you try to use Decimal instead of Double as the following, because it’s Double type accuracy matter?
DT_Test.AsEnumerable().Sum(Function(row) Decimal.Parse(row("Total").ToString))
Sample
BlankProcess_Test20240111v2.zip (13.9 KB)
Regards,
vrdabberu
(Varunraj Dabberu)
January 11, 2024, 7:04am
6
Hi @Lori
Please check the below image and I have attached the workflow for your reference.
BlankProcess_Test20240111.zip (90.3 KB)
Regards
Lori
(Li)
January 11, 2024, 7:15am
7
Your code has the smallest changes, I test , however, it still return wrong data (4.54747350886464E-12)
Lori
(Li)
January 11, 2024, 7:23am
8
Your method works well, however, thanks you very much!
1 Like
vrdabberu
(Varunraj Dabberu)
January 11, 2024, 7:25am
9
Hi @Lori
Thank You.
If you find the solution please do mark my solution as solution to close the loop.
Happy Automation!!
Regards
system
(system)
Closed
January 14, 2024, 7:25am
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.