SqlServer digital information with respect to the decimal point, the decimal point to remove extra zeros

demand:

       For extra zeros after the decimal point with digital information, remove the decimal point

Possible presence of:

    1, within the accuracy of, any excess of zero eg: 1234.3400 desired outcome is 1234.34

    2, the precision becomes large extra zeros occur, there is no actual data or fractional eg: 1234.0 desired result 1234

   3, the end of the data for the decimal point, but no actual decimals eg:. 1234 want results 1234



---- --- removal function to zero decimal places extra zeros select dbo.ClearZero ( '1245.3400') --- result 1245.34 Create function [the dbo]. [ClearZero] (@number VARCHAR (200 is)) Returns VARCHAR (200 is) aS the begin IF @number = '' or null @number iS --- If empty, return to the direct return null the else the begin DECLARE @PointIndex int SET @PointIndex CHARINDEX = ( '.', @ Number The) IF = @PointIndex 0 return @Number --- if not float, return directly if @PointIndex = len (@Number) return replace (@Number, '.', '') ---- last digit decimal point, delete return else the begin if right (@ Number, 1) = '0' --- recursive call to zero operation for the begin SET @number the substring = (Number The @,. 1, len (@number) -. 1) return dbo.ClearZero (@number) End the else return @number End End return null End GO

Guess you like

Origin www.cnblogs.com/jpf111/p/12605338.html