Discuss / Python / float

float

Topic source
from functools import reducedef str1(z):  # z为原字符串    def str_str(x):        a = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}        return a[x]    i = z    i = list(i)    y = z.find('.')    i.pop(y)    i = ''.join(i)    h = reduce(lambda x, y: x * 10 + y, map(str_str, i))    a = z[y + 1:]    a1 = len(a)    p = 1    while a1 > 0:        a1 -= 1        p *= 10    return h / p  # 输出还原小数点的数字,去掉小数点的字符串

from functools import reduce

def str1(z):  # z为原字符串

    def str_str(x):

        a = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}

        return a[x]

    i = z

    i = list(i)

    y = z.find('.')

    i.pop(y)

    i = ''.join(i)

    h = reduce(lambda x, y: x * 10 + y, map(str_str, i))

    a = z[y + 1:]

    a1 = len(a)

    p = 1

    while a1 > 0:

        a1 -= 1

        p *= 10

    return h / p  # 输出还原小数点的数字,去掉小数点的字符串


  • 1

Reply