Floating point is not precise. Try
If Convert.ToInt32(e.TotalPercent * 100.0) = 10000 Then ...
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello
During a process by a 3rd party SDK, I'm getting the progress completion in percent, but not an integer, but single data type!
To check if it reached 100, I use:
If Convert.ToInt32(e.TotalPercent) = 100 Then ...
The problem is this condition will be false for 99.4026 but once it passes 99.5 like 99.54923 it will be true and I will get many true conditions until it reaches 100.
How to safely evaluate a single data type equals exact 100?
Sorry for the newbie question :)
Floating point is not precise. Try
If Convert.ToInt32(e.TotalPercent * 100.0) = 10000 Then ...
Hi @Peter Volz ,
You can use a threshold or a tolerance level for comparison. Since it appears that the progress is provided as a floating-point number, you can check if the value is very close to 100 within an acceptable tolerance level.
Dim progress As Double = e.TotalPercent
Dim tolerance As Double = 0.01 ' Adjust this tolerance level as needed
If Math.Abs(progress - 100.0) < tolerance Then
End If
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.