从数字中获取分数值的可靠方法是什么? [英] What would be a reliable way to get fractional value from a number?
本文介绍了从数字中获取分数值的可靠方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有多个类型 Decimal(8, 2)
并且一直在使用 Substring
来获取小数值.
I have a number of type Decimal(8, 2)
and have been using Substring
to get fractional value.
E.g.)
declare @val decimal(8, 2), @strVal varchar(10)
set @val = 15.80
set @strVal = cast(@val as varchar)
select @val, substring(@strVal, charindex('.', @strVal), len(@strVal))
有没有更好的方法可以简单地从 @val
获取小数值 .80
而不必将其转换为字符?
我想知道是否有一个内置的 UDF(用户定义函数)可以解析而不必推出我自己的版本.
Is there a better way to simply get fractional value, .80
from @val
without having to convert it to a character?
I am wondering if there is a built-in UDF (User-Defined Function) that would parse instead of having to rolling out my own version.
推荐答案
使用模数 (%) 运算符.您将获得 0.80
.
Use the modulus (%) operator. You'll get 0.80
.
像这样:
declare @val decimal(8, 2)
set @val = 15.80
select @val, @val % 1
这篇关于从数字中获取分数值的可靠方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文