Does anyone know a trick to spell out a number on ...
# advancedpdf
n
Does anyone know a trick to spell out a number on an advancedpdf template? e.g. $123.01 would be One Hundred and Twenty Three Dollars and One Cent?
s
I don’t think Freemarker has any built-in for that. However, for numbers up to 5.3 million (5,373,484.99 would be the absolute maximum value) you could define a text formula field in NetSuite on the record with the following formula:
CASE WHEN TRUNC({field}) = 0 THEN 'zero' ELSE TO_CHAR(TO_DATE(TRUNC({field), 'J'), 'jsp') END || ' dollars and ' || CASE WHEN {field} = TRUNC({field}) THEN 'zero' ELSE TO_CHAR(TO_DATE({field} - TRUNC({field}), 'J'), 'jsp') END || ' cents'
slack bookmark 1
👍 1
The above is a trick that converts the number to a Julian date, then to a spelled out version of the Julian date
it would also incorrectly pluralize $1.01 as “one dollars and one cents” but that could be fixed by modifying the CASE statements
n
@scottvonduhn forgot to say thank you! Much appreciated. Had to move it to a script due to some other requirements that changed but I'll keep this one in my back pocket!
s
If using a script, it’s easy enough to find one of numerous JavaScript functions online that have already solved this problem, and plug it in 🙂