如何将浮点数作为文本存储而不会丢失精度? [英] How to store a floating point number as text without losing precision?
本文介绍了如何将浮点数作为文本存储而不会丢失精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在浮点数中保存浮点数而不丢失精度?解决方案我建议使用内置函数 repr()
。从文档:
repr(object) - > string
返回该对象的规范字符串表示形式。
对于大多数对象类型,eval(repr(object))==对象。
Like the question says. Converting to / from the (truncated) string representations can affect their precision. But storing them in other formats like pickle makes them unreadable (yes, I want this too).
How can I store floating point numbers in text without losing precision?
解决方案
I'd suggest using the builtin function repr()
. From the documentation:
repr(object) -> string
Return the canonical string representation of the object. For most object types, eval(repr(object)) == object.
这篇关于如何将浮点数作为文本存储而不会丢失精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文