c# - 点后只保留两位小数

标签 c# ping decimal-point

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”。

我需要它来显示类似:“187.37”

DOT 之后只有两个帖子。有人可以帮帮我吗?

最佳答案

string.Format 是你的 friend 。

String.Format("{0:0.00}", 123.4567);      // "123.46"

关于c# - 点后只保留两位小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1291483/

相关文章:

python - 如何消除Python中subprocess.Popen的标准输出?

c# - Int to Decimal Conversion - 在指定位置插入小数点

binding - 使用 Value With Pattern 绑定(bind)时如何格式化浮点小数?

c# - WPF,XML 数据绑定(bind)到依赖/级联组合框

c# - Unity - 实例化对象上的 GetComponent 返回 Null

c# - C#编译如何避免需要头文件?

ping - 您可以在 Java 中运行真正的 ping 吗?

android shell命令获取结果

python - 让Python range() 识别小数,例如。 70.555555

c# - 使用 ASP.NET Web API 进行错误处理的最佳实践