From 6bb7241627b578e7e176024712d7f4a27b1f7114 Mon Sep 17 00:00:00 2001 From: hyunha Date: Mon, 7 Oct 2024 10:43:26 +0900 Subject: [PATCH] Fix bug where '.' was output when decimals parameter is set to 0 --- formulas/functions/text.js | 5 ++--- test/formulas/text/testcase.js | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/formulas/functions/text.js b/formulas/functions/text.js index a941e3ac..862f5332 100644 --- a/formulas/functions/text.js +++ b/formulas/functions/text.js @@ -136,10 +136,9 @@ const TextFunctions = { number = H.accept(number, Types.NUMBER); decimals = H.accept(decimals, Types.NUMBER, 2); noCommas = H.accept(noCommas, Types.BOOLEAN, false); - - const decimalString = Array(decimals).fill('0').join(''); + const decimalString = decimals > 0 ? '.' + Array(decimals).fill('0').join('') : ''; const comma = noCommas ? '' : '#,'; - return ssf.format(`${comma}##0.${decimalString}_);(${comma}##0.${decimalString})`, number).trim(); + return ssf.format(`${comma}##0${decimalString}_);(${comma}##0${decimalString})`, number).trim(); }, LEFT: (text, numChars) => { diff --git a/test/formulas/text/testcase.js b/test/formulas/text/testcase.js index 835c8ac2..eb2225b3 100644 --- a/test/formulas/text/testcase.js +++ b/test/formulas/text/testcase.js @@ -68,7 +68,9 @@ module.exports = { 'FIXED(12345.64123213)': '12,345.64', 'FIXED(12345.64123213, 5)': '12,345.64123', 'FIXED(12345.64123213, 5, TRUE)': '12345.64123', - 'FIXED(123456789.64, 5, FALSE)': '123,456,789.64000' + 'FIXED(123456789.64, 5, FALSE)': '123,456,789.64000', + 'FIXED(3, 0, false)': '3', + 'FIXED(3000, 0, false)': '3,000' }, LEFT: {