c# - 如何使用 string.Format() 截断而不是舍入?

标签 c# rounding string.format

我想以执行截断而不是舍入的方式应用 string.Format()。例如

string.Format("##", 46.5); // output is 47, but I want 46
string.Format("##.#", 46.55); // output is 46.6, but I want 46.5

最佳答案

使用 Math.Truncate 在格式化输出之前截断

关于c# - 如何使用 string.Format() 截断而不是舍入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15706282/

相关文章:

c# - 为什么一些元组列表是排序的而不是其他的?

c# - 将字典<T,U>转换为字典<T,U.PropertyValue>

javascript - 如何在 Jquery/Javascript 中四舍五入 parseFloat 结果?

java - 设置数组格式以将文本以表格格式附加到 TextField 中

java - 将字符串文字拆分成多行

C# 系统.FormatException : Input string was not in a correct format

c# - 为什么客户端不能与WCF服务器直接对话(!),而不是使用这样做的代理类?

c# - this.Controls 返回 null

php - 四舍五入到最接近的分数(二分之一、四分之一等)

floating-point - "banker' s舍入“真的在数值上更稳定吗?