Strange problem... difference between XP and Win2K3

D

David

Hi all,

I have this code...


if (!AuditFailed)
{
dr["Total number of passed
audits"] = Convert.ToInt32(dr["Total number of passed audits"]) + 1;
Totals++;
TotalPassed++;
}
else
{
dr["Total number of failed
audits"] = Convert.ToInt32(dr["Total number of failed audits"]) + 1;
Totals++;
}

// Calculate Percentage of
satisfactory v unsatisfactory.
if (Totals > 0)
{
//Response.Write("Total:" + Totals + " TotalPassed:" + TotalPassed + "<br
/>");
decimal Satisfactory = (100M
/ Totals) * TotalPassed;
decimal Unsatisfactory =
100M - Satisfactory;
//Response.Write("SAT:" + Satisfactory.ToString("N2") + " UNSAT:" +
Unsatisfactory.ToString("N2") + "<br />");
dr["Percentage of passed
audits"] = Satisfactory.ToString("N2") + " %";
dr["Percentage of failed
audits"] = Unsatisfactory.ToString("N2") + " %";
//Response.Write("drSAT: " + dr["Percentage of passed audits"].ToString() +
" drUNSAT: " + dr["Percentage of failed audits"].ToString() + "<br />");
}

As you can see, I have response.write out to screen to see what is
happening. Ultimately, the display is a gridview.

The Totals and TotalPassed are decimal values. When I response.write to the
screen, I get the correct values, but when I display in gridview, the
Percentage columns are showing 0% and 100%. However, it displays perfectly
on my XP machine.

What is quite weird... I set up the columns by adding them to my DataTable.
I give them intial values of 100% and 0%. I then do the calculation as above
and populate the values. However, if I get any unsatisfactory, the
percentage of failed audits becomes 100% (100.00%). (It should be 40%)

I am really puzzled about this. (Initially, I didn't have 100M, I just had
100, but this didn't work either, whilst it worked fine on my XP machine.)

Any pointers would be very much appreciated.

This is .NET 2.0
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
N

Nicholas Hurd

If your percentage calculation is working correctly and displaying correctly
when using Response.Write then it's most likely that you should look for
your problem in the grid view display. It may be helpful include the code
that binds your calculation results to the grid in case that is the issue.
 
D

David

Hi,

It was nothing to do with the gridview display. The same calculation routine
also pushes out to a CSV file. I have found the problem...

It was actually down to two tables apparently having some form of unstable
data. I don't know what was unstable, but something was causing the
problem... the unstable data being on the live server, not my local dev
machine.

I have two percentage calculation parts. I have moved both of them out of
the 'build' loop that gets all the data from the database and moved them
into another loop that actually does other calculations. This has fixed the
problem. With the move, I think it should also make the app slightly faster
(in this particular case) as the first loop was a loop inside a loop, and
the other calculation loop is just one loop. (Too complicated to explain, it
was complicated enough to write it in the first place)

Took me ages to find it. I had to put in my response.write at various loop
(and if statement) closing braces to see what was happening.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


Nicholas Hurd said:
If your percentage calculation is working correctly and displaying
correctly when using Response.Write then it's most likely that you should
look for your problem in the grid view display. It may be helpful include
the code that binds your calculation results to the grid in case that is
the issue.

David said:
Hi all,

I have this code...


if (!AuditFailed)
{
dr["Total number of passed
audits"] = Convert.ToInt32(dr["Total number of passed audits"]) + 1;
Totals++;
TotalPassed++;
}
else
{
dr["Total number of failed
audits"] = Convert.ToInt32(dr["Total number of failed audits"]) + 1;
Totals++;
}

// Calculate Percentage of
satisfactory v unsatisfactory.
if (Totals > 0)
{
//Response.Write("Total:" + Totals + " TotalPassed:" + TotalPassed + "<br
/>");
decimal Satisfactory =
(100M / Totals) * TotalPassed;
decimal Unsatisfactory =
100M - Satisfactory;
//Response.Write("SAT:" + Satisfactory.ToString("N2") + " UNSAT:" +
Unsatisfactory.ToString("N2") + "<br />");
dr["Percentage of passed
audits"] = Satisfactory.ToString("N2") + " %";
dr["Percentage of failed
audits"] = Unsatisfactory.ToString("N2") + " %";
//Response.Write("drSAT: " + dr["Percentage of passed audits"].ToString()
+ " drUNSAT: " + dr["Percentage of failed audits"].ToString() + "<br
/>");
}

As you can see, I have response.write out to screen to see what is
happening. Ultimately, the display is a gridview.

The Totals and TotalPassed are decimal values. When I response.write to
the screen, I get the correct values, but when I display in gridview, the
Percentage columns are showing 0% and 100%. However, it displays
perfectly on my XP machine.

What is quite weird... I set up the columns by adding them to my
DataTable. I give them intial values of 100% and 0%. I then do the
calculation as above and populate the values. However, if I get any
unsatisfactory, the percentage of failed audits becomes 100% (100.00%).
(It should be 40%)

I am really puzzled about this. (Initially, I didn't have 100M, I just
had 100, but this didn't work either, whilst it worked fine on my XP
machine.)

Any pointers would be very much appreciated.

This is .NET 2.0
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Top