如何在json转储中将float格式化为4位小数?

时间:2017-11-14 09:55:15

标签: python json floating-point decimal

难以将pf_stats输出转换为4位小数:

def run_simulation(H, P, B, C, mu, sigma, T, L):

    x = normal(mu, sigma, (L, T))

    pf_all = []

    for xs in x:
        pf = calc(xs, H, P, B, C)
        pf_all.append(pf)

    pf_means = np.mean(pf_all, axis=1)

    funcs = [np.average, np.median, np.min, np.max]
    func_names = ["Average", "Median", "Min", "Max"]

    pf_stats= [f(pf_means) for f in funcs]


    return json.dumps({
        'functions' : func_names,
        'pf_stats' : pf_stats
    })

0 个答案:

没有答案