What do I do if I want to remove the extra 0 from the decimal point in SQL?
Select 5000/10000.0--Want to become 0.5
Select 5500/10000.0--Want to become 0.55
Select 5550/10000.0--Want to become 0.555
Select 5555/10000.0--Want to become 0.5555
The results were: 0.5000000 0.5500000 0.5550000 0.5555000
First, if you want to remove the number 5 after the excess 0, need to convert:
Select CONVERT (float,5000/10000.0)--want to become 0.5
Select CONVERT (float,5500/10000.0)--want to become 0.55
Select CONVERT (float,5550/10000.0)--want to become 0.555
Select CONVERT (float,5555/10000.0)--want to become 0.5555
The results were: 0.5 0.55 0.555 0.5555
Second, create the function:
In SQL Server, create a function Clearzero, use this function to remove the extra 0 after the decimal point.
CREATE function [dbo]. [Clearzero] (@inValue varchar (50))
Returns varchar (50)
As
Begin
DECLARE @returnValue varchar (20)
if (@inValue = ")
Set @returnValue = "--Empty when empty
else if (charindex ('. ', @inValue) = ' 0 ')
Set @[email protected]--for non-decimal
else if (substring (reverse (@inValue), Patindex ('%[^0]% ', reverse (@inValue)), 1) = '. ')
Set @returnValue =left (@inValue, Len (@inValue)-patindex ('%[^0]% ', reverse (@inValue)))--for all 0 after the decimal point
Else
Set @returnValue =left (@inValue, Len (@inValue)-patindex ('%[^0]%.% ', reverse (@inValue)) +1)--any other situation
Return @returnValue
End
Another: In C #?
Decimal d = 0.0500m;
D.tostring ("0.##") came out.
You can also do this string. Format ("{0:0.##}", d000)
SQL Server removes the extra 0 after the decimal point