c# - 百分比计算

标签 c# asp.net asp.net-mvc-2 drop-down-menu

我正在研究 ASP.NET MVC 2 中的进度条概念。这里我有一个包含 10 个值的 DropDownList。我想计算进度条的百分比,例如来自 DropDownList 的 10 个值,我有一个返回值 2 的查询。因此,在 10 个值中,我得到 2。应该显示“20% 已完成”。如何进行此计算

最佳答案

使用 Math.Round():

int percentComplete = (int)Math.Round((double)(100 * complete) / total);

或手动舍入:

int percentComplete = (int)(0.5f + ((100f * complete) / total));

关于c# - 百分比计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4561374/

相关文章:

asp.net - 我们可以通过客户端浏览器看到 html localstorage 内容吗?

c# - 如何正确设置用于调试的 silverlight 应用程序?

html - Gridview 标题向左对齐,在 IE9 上不起作用,但在 chrome 上有效

.NET MVC - 如何从另一个 Controller 获取 JsonResult?

asp.net-mvc - jQuery + Ajax + 加载旋转图像 = 太快了!

c# - 使用 PlayerPrefs 的 Unity Highscore 无法正常工作

c# - Entity Framework - 大写第一个属性名称字母

asp.net-mvc-2 - EF CTP5 错误 : Invalid object name

c# - 如何从 C# 代码中拉伸(stretch) DataGrid 列?

C#、 Selenium 网络驱动程序