如何转换为加倍与2 precision - 串点后?转换为、precision、串点后

2023-09-02 20:47:28 作者:原味少女心

我想这个字符串转换: 0.55000000000000004 来这双: 0.55 。 那怎么办?

I want to convert this string: 0.55000000000000004 to this double: 0.55. How to do that?

推荐答案

是一个字符串或双? 如果它是一个字符串:

Is a string or a double? If it is a string:

double d = double.Parse(s,CultureInfo.InvariantCulture);
string s=string.Format("{0:0.00}",d);

,如果它已经使用第二线的双重只是格式

if it is already a double just format using the second line.