Python Forum
f-strings round float down too much
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
f-strings round float down too much
#1
Output:
lt2a/forums /home/forums 4> cp -ft. /home/phil/foo.py '/home/phil/foo.py' -> './foo.py' removed './foo.py' lt2a/forums /home/forums 5> cat foo.py from decimal import Decimal from numpy import nextafter a = nextafter(0.0,1) d = Decimal(a) print('a =',a) print('d =',d) print('a =',repr(a)) print(f'a = {a}') print(f'd = {d}') print(f'a = {a!r}') lt2a/forums /home/forums 6> python3.6 foo.py a = 4.94065645841e-324 d = 4.940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625E-324 a = 4.9406564584124654e-324 a = 5e-324 d = 4.940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625E-324 a = 4.9406564584124654e-324 lt2a/forums /home/forums 7>
so, maybe it's fixed in 3.10.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
f-strings round float down too much - by Skaperen - Dec-29-2021, 12:16 AM
RE: f-strings round float down too much - by casevh - Dec-29-2021, 07:25 AM
RE: f-strings round float down too much - by casevh - Dec-29-2021, 04:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print a list strings is fast but printing the joined strings is slow Skaperen 9 4,101 Aug-26-2019, 07:48 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020