如何转换为具有 2 个精度的双精度 - 点后的字符串? [英] How to convert to double with 2 precision - string after dot?

查看:9
本文介绍了如何转换为具有 2 个精度的双精度 - 点后的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将这个字符串: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.

这篇关于如何转换为具有 2 个精度的双精度 - 点后的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆