DataView data vs. Field Value

I am trying to do some math on LaborDtl.LaborHrs and compare it to the LaborHed.PayHours in a customization and it is often off by .01

After digging I see that the field value is .41667 but when I use the following iteration:

foreach(DataRowView row in myEDV.dataView)
{
MessageBox.Show(row[“LaborDtl.LaborHrs”].ToString());
}

…it reports .42

What is the easiest way around this? I tried converting the value to double as well as setting extended properties but it still comes through as .042000 rounding up.

Thank you,
Ross

The string of the field value is going to round it but the math should be performed on the datatype of that field. Are you just asking why the string is a rounded version?

1 Like

That field is already a decimal, you are doing a .ToString() on it and thus turning it into a string. When you do math do math directly on the field. As @Aaron_Moreng suggested.

1 Like

Okay, so the string is presenting it rounded…I see.

I have used double and decimal in the math and when it is done it is still using .42 instead of .41167

for example, looping the following is using .42 and .02 and I get 10.11 as a result in the math.

decimal totalLaborHours = 0;
foreach(DataRowView row in myEDV.dataView)
{
totalLaborHours = totalLaborHours + (decimal)row[“LaborDtl.LaborHrs”];
}

I have 3 LaborHrs records:
9.67
0.41667
0.01667

Manual math gives me 10.10334

When I look in to Time and Expense Entry I see this:

image

I must be doing something wrong but I can’t see it and will keep looking…

Thanks,
Ross

Ugh, found it…sorry. I was iterating through a dashboard view and the BAQ itself was formatting to a >>9.99 on the LaborHrs field and I was iterating through that thinking I was drawing it from an adapter dataset field.

Sorry for the confusion and thank you for the assistance.

Ross

2 Likes