How to make my script force numbers to two decimal places

3,909 views
Skip to first unread message

Ranbir Calay

unread,
Jun 30, 2022, 10:58:03 AM6/30/22
to Google Apps Script Community
Hey all

I've currently got a script that auto fills a Google Doc Template from Sheet data.

The problem I have is when the script fills out a field meant for money. I can set the cell format to currency but the script seems to only read the absolute value which ignores decimal places that have a zero in them.

For example, if my cell is formatted to show currency which is £3.50. I can run the script and the Doc Template will be populated but it will display only as 3.5. Is there a way I can force the script to make sure it prints 3.50?

Please and Thank you


Edward Ulle

unread,
Jun 30, 2022, 1:22:54 PM6/30/22
to Google Apps Script Community
How about Number.toFixed(2).  https://www.w3schools.com/jsref/jsref_tofixed.asp

Ranbir Calay

unread,
Jul 4, 2022, 8:07:33 AM7/4/22
to Google Apps Script Community
Thank you very much, it works.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages