我怎样才能在SQL小数的分数小数、分数、SQL

2023-09-04 00:17:43 作者:几羽霓裳舞倾城

我有一个十进制值34.3287332我怎么能得到的价值的部分像0.3287332请任何一个帮助(我可以转换为字符串,并获得分数。但我不需要)

I've a decimal value 34.3287332 how can i get the fraction of the value like .3287332 please any one help (I can convert that to string and get the fraction. but i dont need to)

推荐答案

我只取整数值,然后得到的余数:

I would just fetch the whole value, and then get the remainder:

decimal total = /* get value from database */;
decimal fraction = decimal.Remainder(total, 1m);

(有可能是一种更有效的方式来获得其余部分,但这是pretty的简单。)

(There may be a more efficient way to get the remainder part, but this is pretty simple.)

当你能做到这一点的SQL作为好,这是有可能的工作不太好,当你想获取使用LINQ的值,以SQL或任何类似的 - 我preFER把价值操纵在.NET $ C $ Ç而不是在SQL中,除非它影响的结果或性能

While you could do this in SQL as well, that's likely to work less well when you want to fetch the values with LINQ to SQL or anything similar - I prefer to put value manipulation in the .NET code rather than in the SQL, unless it affects the results or performance.