/// <summary> /// 根据精度将金额转换为自定义类型的string /// </summary> /// <param name="precision">需要的精度</param> /// <param name="money">需要转换的金额</param> /// <returns>转换后的金额</returns> public string FormateString(int precision, double money) { //比如,FormateString(2,2333)==>结果:2,333.00 string format = "###,###,###,##0."; for (int i = 0; i < precision; i++) { format = format + "0"; } return money.ToString(format); } /// <summary> /// 转换任意类型的对象为Double /// </summary> /// <param name="val">需要转换的对象</param> /// <returns>返回Double类型的变量</returns> public double ConvertDouble(object val) { if (((val == null) || (val.ToString() == "")) || (val is DBNull)) { return 0.0; } if (val is string) { val = val.ToString().Replace(",", ""); } try { return Convert.ToDouble(val); } catch { return 0.0; } }
小注:
自定义格式显示:点击打开链接
时间: 2024-09-11 17:49:49