c# - C# 中的 DataFormatString 舍入问题

标签 c# asp.net-mvc-4

我目前有一个问题导致我的程序中的货币四舍五入。如果它是 7 位数字,它会自动将其四舍五入,我无法理解这个问题。

例如:

100000.99 存储到 DB 时会自动向上取整为 100001.00。

但是,如果我有少于六位数的任何内容,它就会被正确存储。

[Display(Name = "PO Value")]
[DisplayFormat(DataFormatString = "{0:C}")]
public float POValue { get; set; }

有什么建议吗?

该应用程序是使用 C# 和 MVC4 引擎在 Visual Studio 2010 中构建的。

最佳答案

感谢 Michael Coxon 我已经解决了这个问题!在 DB 中,列 POValue 设置为真实的 DataType。因此精度只有 7,这说明了我的问题。我正在将其修改为 DataType float 。

关于c# - C# 中的 DataFormatString 舍入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40998687/

相关文章:

asp.net - 发布 ASP.NET MVC 4 时 Controller 和类无法编译

c# - AssemblyBinding BindingRedirect 不适用于带有 T4MVCExtensions 的 MVC4 应用程序

c# - 无法在asp.net core 2.0 Web App中实现功能文件夹

具有多个泛型类型的 C# 函数调用

c# - Xamarin Ios 应用程序在调试时运行时卡住

C#:无法创建 DirectX 设备。硬件类型或软件类型均无效

c# - Func<Owned<T>> 与 Func<T> 依赖关系

c# - Xamarin.iOS:Firebase 推送通知不起作用

jquery - session 超时时调用 Ajax

c# - PartialView 方法返回 Null(似乎根本没有调用 View )