//参数:d表示要四舍五入的数;i表示要保留的小数点后为数。 /// <summary> /// 四舍五入 /// </summary> /// <param name="d">计算的数</param> /// <param name="i">要保留的小数点后为数</param> /// <returns>四舍五入结果</returns> public static double Round(double d, int i) { if (d >= 0) { d += 5 * Math.Pow(10, -(i + 1)); } else { d += -5 * Math.Pow(10, -(i + 1)); } string str = d.ToString(); string[] strs = str.Split('.'); int idot = str.IndexOf('.'); string prestr = strs[0]; string poststr = (strs.Length < 2) ? "0" : strs[1]; if (poststr.Length > i) { poststr = str.Substring(idot + 1, i); } poststr = (poststr.Length == 0) ? "0" : poststr; string strd = prestr + "." + poststr; d = Double.Parse(strd); return d;
四舍五入
最新推荐文章于 2024-07-11 22:26:33 发布
本文介绍了一种实现自定义精度四舍五入的方法。通过给定的参数,该方法能够对任意浮点数进行精确到指定小数位的四舍五入操作。此算法适用于需要精确数值处理的应用场景。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率
1278

被折叠的 条评论
为什么被折叠?



