Skip to content

Commit 9e76155

Browse files
authored
fixes #31 and #33 (#32)
* fixes #31 by clearing the @vSubResult variable, even if @v000Num <> 0 * fixes #33 by suppressing the dash after twenty, thirty, forty, etc, when the 1's column is 0 (includes updated test image, too)
1 parent 9a05ead commit 9e76155

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

core/MoneyToWords_EN.sql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ BEGIN
7171
SET @v000Num = @Number % 1000
7272
SET @v00Num = @v000Num % 100
7373
SET @v0Num = @v00Num % 10
74-
IF @v000Num = 0
75-
BEGIN
76-
SET @vSubResult = ''
77-
END
78-
ELSE
74+
SET @vSubResult = ''
75+
IF @v000Num > 0
7976
BEGIN
8077
--00
8178
IF @v00Num < 20
@@ -90,7 +87,7 @@ BEGIN
9087
-- greater than or equal 20
9188
SELECT @vSubResult = Nam FROM @tDict WHERE Num = @v0Num
9289
SET @v00Num = FLOOR(@v00Num/10)*10
93-
SELECT @vSubResult = FORMATMESSAGE('%s-%s', Nam, @vSubResult) FROM @tDict WHERE Num = @v00Num
90+
SELECT @vSubResult = FORMATMESSAGE('%s%s', Nam, COALESCE('-' + NULLIF(@vSubResult, ''), '')) FROM @tDict WHERE Num = @v00Num
9491
END
9592

9693
--000
@@ -142,4 +139,5 @@ END
142139
SELECT dbo.MoneyToWords_EN(123234567896789.02)--123 234 567 896 789.02
143140
SELECT dbo.MoneyToWords_EN(999999999999999.99)--999 999 999 999 999.99
144141
SELECT dbo.MoneyToWords_EN(100000000000000)
142+
SELECT dbo.MoneyToWords_EN(20200.01)
145143
*/

test/MoneyToWords-EN.png

0 Bytes
Loading

0 commit comments

Comments
 (0)