LINQ to SQL Math.Round问题 [英] LINQ to SQL Math.Round Problem

查看:113
本文介绍了LINQ to SQL Math.Round问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的查询存在问题,由于某种原因,我用来存储小数的变量在小数点后返回6个值(它们大多为0).

I'm having an issue with a query I wrote where for some reason the variable that I'm using to store a decimal value in returns 6 values after the decimal place (they're mostly 0).

我没有运气尝试过以下方法(以及使用Math.Round的不同组合).

I have tried the following (and different combinations using Math.Round) with no luck.

Sales =
          (from invhed in INVHEAD 
           ... // Joins here
           orderby cust.State ascending
           select new Sale
           {
                InvoiceLine = inv.InvoiceLine,
                InvoiceNum = inv.InvoiceNum,
                ...
                NetPrice = Math.Round((inv.ExtPrice - inv.Discount) * (Decimal) (qsales.RepSplit / 100.0), 2, MidpointRounding.ToEven),
           }).ToList<Sale>();

NetPrice成员具有类似300.000000、5000.500000、3242.520000等的值.

The NetPrice member has values like 300.000000, 5000.500000, 3245.250000, etc.

有任何线索吗?我似乎在网上找不到关于此问题的任何内容.

Any clues? I can't seem to find anything on this issue online.

Decimal.Round可以解决问题(我忘了提到NetPrice成员是Decimal类型).请在下面查看我的答案.

Decimal.Round did the trick (I forgot to mention that the NetPrice member was a Decimal type). See my answer below.

推荐答案

我使用Decimal.Round()和以前相同的参数来使它工作. :)

I got it to work using Decimal.Round() with the same arguments as before. :)

看起来问题有点像Pavel所说的那样,十进制类型的行为不同,看起来像Math.Round并没有像他们期望的那样与它们一起工作...

Looks like the issue is somewhat on the trail of what Pavel was saying, where Decimal types behave differently and it would seem Math.Round doesn't quite work with them as one would expect it to...

感谢所有输入.

这篇关于LINQ to SQL Math.Round问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆