gpt4 book ai didi

c# - 四舍五入小数位不起作用?

转载 作者:行者123 更新时间:2023-11-30 19:59:50 26 4
gpt4 key购买 nike

这样做:

double dblRateEvalResult = -0.52;
string strNewResult = dblRateEvalResult.ToString("000.####").TrimStart('-');

我要:

000.5200

我得到:

000.52

我做错了什么?

最佳答案

您需要 0 自定义说明符而不是 #

string str =  dblRateEvalResult.ToString("000.0000").TrimStart('-');

(在您的代码中,您试图将字符串分配给 double 值,我猜这是一个错字)

参见:The "0" custom format specifier - Custom Numeric Format Strings

If the value that is being formatted has a digit in the position where the zero appears in the format string, that digit is copied to the result string; otherwise, a zero appears in the result string.

关于c# - 四舍五入小数位不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22714829/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com