#数字转字符保留几位小数 by gisoracle

#数字转字符保留几位小数 by gisoracle

#数字转字符保留几位小数  by gisoracle
def floattostr(num,xsnum):
    if xsnum==0:
        return str(int(num))
    nd=round(num,xsnum)
    nstr=str(nd)
    idx=nstr.index('.')
    print idx
    p=len(nstr)-idx-1
    print p
    n=xsnum-p
    print n
    s=""
    for i in range(n):
        s=s+"0"

    return nstr+s

猜你喜欢

转载自www.cnblogs.com/gisoracle/p/11297119.html