当前位置: 代码迷 >> 综合 >> c# 浮点数取小数点后两位
  详细解决方案

c# 浮点数取小数点后两位

热度:52   发布时间:2024-01-15 02:58:41.0

浮点数取小数点后两位(不舍入):

    double d="12.345";  string str=d.ToString();  int count=str.LastIndexOf(".");  double d1=Double.Parse(str.SubString(0,count+2));  //output d1=12.34  



浮点数保留小数点后两位(舍入):

double d="12.34";  double d1=Double.Parse(d.ToString("2F"));  //output d1=12.35  



  相关解决方案