点后,只留下两位小数 [英] Leave only two decimal places after the dot
本文介绍了点后,只留下两位小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void LoadAveragePingTime()
{
try
{
PingReply pingReply = pingClass.Send("logon.chronic-domination.com");
double AveragePing = (pingReply.RoundtripTime / 1.75);
label4.Text = (AveragePing.ToString() + "ms");
}
catch (Exception)
{
label4.Text = "Server is currently offline.";
}
}
目前我label4.Text获取的是这样的:187.371698712637
Currently my label4.Text get's something like: "187.371698712637".
我需要它来显示类似:187.34
I need it to show something like: "187.34"
后点只有两个职位。有人可以帮我吗?
Only two posts after the DOT. Can someone help me out?
推荐答案
的String.Format
是你的朋友。
String.Format("{0:0.00}", 123.4567); // "123.46"
这篇关于点后,只留下两位小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文