How to fix output


#1

Heres my code: I don’t now how to fix the the 2nd column output. sin of (2 * pi) = sin (360) is supposed to be zero. I guess this is because of the inaccuracy of decimals. How do I just make it display 0.0000. Also, how would I all together try and handle decimals to get accurate results. Thanks a lot.


#2

For consideration:

>>> from math import sin, pi
>>> sin(0)
0.0
>>> sin(0) or 0
0
>>> round(sin(pi), 4)
0.0
>>> round(sin(pi), 4) or 0
0
>>> sin(pi/2)
1.0
>>> round(sin(pi/2), 4)
1.0
>>> round(sin(pi/2), 4) and 1
1
>>> round(sin(2 * pi), 4) or 0
0
>>> (round(sin(2 * pi), 4) or 0) and 0
0
>>> 

#3

Another possibility is to use the expression …

int(10000 * math.sin(radian)) / 10000.0

… in place of …

math.sin(radian)

Use a similar technique for the cosine calculation.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.