Original: SQL removes all 0 digits after the decimal point number
- The first of these methods
Select CAST (2.5000000000000 as Real) select CAST (2 as Real) select cast (2.00000 as Real)
CREATE function [dbo]. [Clearzero] (@inValue varchar) returns varchar (asbegindeclare @returnValue varchar (@inValue = ") Set @returnValue = '- -Empty when an else if (charindex ('. ', @inValue) = ' 0 ') set @[email protected]--for else if (substring (reverse (@inValue) with no decimal point, Patindex ('%[^0]% ', reverse (@inValue)), 1) = '. ') Set @returnValue =left (@inValue, Len (@inValue)-patindex ('%[^0]% ', reverse (@inValue)))--for the else set that is all 0 after the decimal point @retur Nvalue=left (@inValue, Len (@inValue)-patindex ('%[^0]%.% ', reverse (@inValue)) +1)--Any other case return @returnValueend
SQL removes all 0 after the decimal point valid number