Converting a Python Float to a String without losing precision

后端 未结 5 825
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 03:40

I am maintaining a Python script that uses xlrd to retrieve values from Excel spreadsheets, and then do various things with them. Some of the cells in the spreadshe

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 04:31

    EDIT: Cleared my previous answer b/c it didn't work properly.

    I'm on Python 2.6.5 and this works for me:

    a = 0.38288746115497402
    print repr(a)
    type(repr(a))    #Says it's a string
    

    Note: This just converts to a string. You'll need to convert to Decimal yourself later if needed.

提交回复
热议问题