Jon*_*eet 22
看看Math.Round(decimal)或带有MidpointRounding参数的重载.
当然,您需要解析并格式化值以将其从/到文本.如果这是用户输入的输入,您应该使用decimal.TryParse返回值来确定输入是否有效.
string text = "19500.55";
decimal value;
if (decimal.TryParse(text, out value))
{
value = Math.Round(value);
text = value.ToString();
// Do something with the new text value
}
else
{
// Tell the user their input is invalid
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
55465 次 |
| 最近记录: |