46 lines
1.2 KiB
HTML
46 lines
1.2 KiB
HTML
<div id="sina_keyword_ad_area2" class="articalContent ">
|
|
<div>
|
|
<ul>
|
|
<li>第一种方法</li>
|
|
</ul>
|
|
</div>
|
|
<div>select cast(2.5000000000000 as real)</div>
|
|
<div>select cast(2 as real)</div>
|
|
<div>select cast(2.00000 as real)</div>
|
|
<div> </div>
|
|
<div> </div>
|
|
<div>
|
|
<ul>
|
|
<li>第二种方法</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
<div>CREATE function [dbo].[ClearZero](@inValue varchar(50))</div>
|
|
<div>returns varchar(50)</div>
|
|
<div>as</div>
|
|
<div>begin</div>
|
|
<div>declare @returnValue varchar(20)</div>
|
|
<div>if(@inValue='')</div>
|
|
<div> set @returnValue=''
|
|
--空的时候为空</div>
|
|
<div>else if (charindex('.',@inValue) ='0')</div>
|
|
<div> set @returnValue=@inValue
|
|
--针对不含小数点的</div>
|
|
<div>else if (
|
|
substring(reverse(@inValue),patindex('%[^0]%',reverse(@inValue)),1)='.')</div>
|
|
<div>
|
|
set @returnValue
|
|
=left(@inValue,len(@inValue)-patindex('%[^0]%',reverse(@inValue)))
|
|
--针对小数点后全是0的</div>
|
|
<div>
|
|
else</div>
|
|
<div>
|
|
set @returnValue
|
|
=left(@inValue,len(@inValue)-
|
|
patindex('%[^0]%.%',reverse(@inValue))+1) --其他任何情形</div>
|
|
<div>return @returnValue</div>
|
|
<div>end</div>
|
|
|
|
</div>
|
|
<p> </p> |