简体   繁体   English

将尾随零添加到浮动小数

[英]Adding trailing zeros to floating decimals

I am trying to write some floats numbers as decimals with 14 digit after floating point.我正在尝试将一些浮点数写为浮点数后 14 位的小数。 So i want to add traling zeros for numbers who have less than 14 digits.所以我想为少于 14 位的数字添加跟踪零。 however, when I use the folowing, it performs a random approximation rather than adding zeros.但是,当我使用以下内容时,它会执行随机近似而不是添加零。

print ('%.14f' % 381.949875)
print ('%.14f' % 383.558625 )
print ( '%.14f' % 382.593375)

The result is as follows:结果如下:

381.94987500000002
383.55862500000001
382.59337499999998

Any clue?有什么线索吗?

You are looking for this formatting I believe我相信您正在寻找这种格式

f"{381.949875:0<14}"
f"{383.558625:0<14}"
f"{382.593375:0<14}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM