Question : VB equation is slightly off

Can someone tell my why this equation will be inaccurate?

valu = 2 * txtR.Text * (Math.Tan(Math.PI * txtA.Text / 180) / 2) + txtE.Text / Math.Tan(Math.PI * txtA.Text / 180)

valu as decimal.

VB calculates: 249.64617092752
My calculator: 249.200328

and ideas as to why theres a difference? thats nearly a half of an inch.

Answer : VB equation is slightly off

What happens if you use explicit type conversion and .Value instead of .Text, i.e.

    Dim A As Double
    A = CDbl(txtA.Value) * Math.Pi / 180

And then use A in the equation (and the same for R and E)?

What are the values of your text boxes when you perform the calculation? Also note that if "your calculator" is Windows, it performs 64-bit operations, not 32-bit, but without the original values, I can't measure the impact.

    VB: PI = 3.14159265358979
    Calc: PI = 3.1415926535897932384626433832795

(°v°)
Random Solutions  
 
programming4us programming4us