我怎样才能在SQL小数的分数 [英] how can I get the fraction of the decimal in sql

查看:167
本文介绍了我怎样才能在SQL小数的分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个十进制值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.

这篇关于我怎样才能在SQL小数的分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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