科学计数浮点数变成字符串

https://codeday.me/bug/20171224/112503.html

import decimal

# create a new context for this task
ctx = decimal.Context()

# 20 digits should be enough for everyone :D
ctx.prec = 20

def float_to_str(f):
    """
    Convert the given float to a string,
    without resorting to scientific notation
    """
    d1 = ctx.create_decimal(repr(f))
    return format(d1, 'f')

猜你喜欢

转载自blog.csdn.net/lucyxu107/article/details/84586178