Created
September 18, 2013 20:23
-
-
Save ycaroafonso/6615094 to your computer and use it in GitHub Desktop.
Converte números no formato Decimal para R$ por extenso. Precisa da Function https://gist.github.com/ycaroafonso/6614586
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION ConvertDecimalParaRealPorExtenso(@Num DECIMAL(8, 2)) | |
RETURNS VARCHAR(500) | |
AS BEGIN | |
DECLARE @Ret VARCHAR(500) = '' | |
DECLARE @N1 INT = FLOOR(@Num) | |
DECLARE @N2 INT = REPLACE(CAST(@Num - FLOOR(@Num) AS VARCHAR(20)), '0.', '') | |
IF(@N1 > 0) BEGIN | |
SET @Ret = dbo.NumeroExtenso(@N1) | |
IF(@N1 > 1) SET @Ret += ' reais' | |
else SET @Ret += ' real' | |
END | |
IF(@N2 > 0) BEGIN | |
IF(@Ret <> '') SET @Ret += ' e ' | |
SET @Ret += dbo.NumeroExtenso(@N2) | |
IF(@N2 > 1) SET @Ret += ' centavos' | |
else SET @Ret += ' centavo' | |
END | |
RETURN @Ret | |
END | |
GO | |
SELECT dbo.ConvertDecimalParaRealPorExtenso(1.5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment