I have a donations webpage where people can specify what percentage of their donation goes to what charity. I have validation in place to ensure that they cannot allocate more than 100%. This works fine until people add decimal values.
The percentages are stored on a SQL database as floats, and I bring in the total percentage available to allocate using the following stored procedure.
SELECT giftid, SUM(percentage) totalPercentage
FROM dbo.giftFundArea
WHERE giftid = @giftid
GROUP BY giftid
My page looks at the stored procedure and accesses the value using the following code.
Dim percentageAllocated As Double = myReader.GetDouble(myReader.GetOrdinal("totalPercentage"))
When I run the stored procedure in Managememt Studio I see that the total percentage allocated for a particular gift is 33.4% but when I debug my page I see that percentageAllocated has a value of 33.400000000000006%.
This is obviously throwing off my validation.
Can anyone suggest how I stop this incorrect conversion?
Thanks in advance.