Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print '-'*60
- n = 0.387951
- print n # 0.387951
- print round(n, 3) # 0.388
- print format(n, '.18f') # 0.387950999999999990
- print n*0.000001 # 3.87951e-07
- print format(n*0.000001, '.18f') # 0.000000387951000000
- print '%.8f' % n # 0.38795100
- print '%.10f' % n # 0.3879510000
- print '%.12f' % n # 0.387951000000
- print '%.14f' % n # 0.38795100000000
- print '%.16f' % n # 0.3879510000000000 <- sechzehnte Nachkommastelle noch "in Orndung"
- print '%.17f' % n # 0.38795099999999999 <- ab siebzehnter Nachkommastelle faellt die Abweichung auf
- print '%.18f' % n # 0.387950999999999990
- print n # 0.387951 <- n ist nach wie vor unveraendert
- print '-'*60
- n = 0.1
- print n # 0.1
- print round(n, 3) # 0.1
- print format(n, '.18f') # 0.100000000000000006
- print n*0.000001 # 1e-07
- print format(n*0.000001, '.18f') # 0.000000100000000000
- print '%.8f' % n # 0.10000000
- print '%.10f' % n # 0.1000000000
- print '%.12f' % n # 0.100000000000
- print '%.14f' % n # 0.10000000000000
- print '%.16f' % n # 0.1000000000000000 <- sechzehnte Nachkommastelle noch "in Orndung"
- print '%.17f' % n # 0.10000000000000001 <- ab siebzehnter Nachkommastelle faellt die Abweichung auf
- print '%.18f' % n # 0.100000000000000006
- print '-'*60
- a, b, c = 0.1, 0.1, 0.1
- print a + b + c # 0.3
- print a + b + c == 0.3 # False
- print '%.16f' % a # 0.1000000000000000
- print '%.17f' % a # 0.10000000000000001
- print '%.17f' % (a+b+c) # 0.30000000000000004
- print '-'*60
- import decimal
- from decimal import Decimal, Context
- print Decimal(0.1) # 0.1000000000000000055511151231257827021181583404541015625
- print Decimal('0.1') # 0.1
- a = Decimal('0.1')
- b = Decimal('0.1')
- c = Decimal('0.1')
- print a + b + c == Decimal('0.3') # True
- print a + b + c == 0.3 # False
- print format(Decimal('0.1'), '.20f') # 0.10000000000000000000
- print format(Decimal(0.1), '.20f') # 0.10000000000000000555
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement