@ Introduction to Python for science and technology calculation ――Development basics, essential libraries, acceleration by Kenji Nakahisa (Target environment: Python 3.5 or later)
In the unittest function, round (a-b, 7) == 0
was introduced as the processing of ʻassertAlmostEqual (a, b)`.
Related: http://qiita.com/aomidro/items/3e3449fde924893f18ca
I haven't learned round () yet.
link
https://docs.python.jp/3/library/functions.html#round ** Please note the notes **
code
I tried using it.
http://ideone.com/6lVook
# 12345678
in1 = 3.1415926
in2 = 3.14159265
dif = round(in1 - in2, 7)
print("%.8f" % dif)
# 123456789
in1 = 3.14159265
in2 = 3.141592653
dif = round(in1 - in2, 7)
print("%.8f" % dif)
run
-0.00000010
-0.00000000
Recommended Posts