Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to compare the floating type value in my code like

if sum=1.0 then
Code statements true
else
code statements false
end if
but what happened is sometimes even if the sum is 1.0 then also
it goes to else block of code . How do I solve this ?
Posted
Comments
syed shanu 21-Apr-14 1:55am    
what data type is your sum
Ni!E$H_WAGH 21-Apr-14 2:00am    
Float
Ajith K Gatty 21-Apr-14 1:56am    
hi
Use TryParse and implement the code.
syed shanu 21-Apr-14 2:24am    
Double sums;
sums = 1.0;
string s;
if (sums == 1.0)
{
s = "welcome";
}
else
{
s = "test";
}
MessageBox.Show(s);

1 solution

Go through http://www.vb-helper.com/howto_net_compare_float.html[^].
Use something like CStr(Math.Abs(sum - 0) < 0.00001).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900