Formatting Numbers in Document Generation
Hello
I have a couple of numbers that I take from a list and put them into a generated word through the document generation feature. It would be nice to be able to format them with for instance with a "thousand marker" for instance 123'000 instead of 123000. I assume it is possible but I simply do not see how. The fielddef in the list is a number field.
Thanks for your time.
-
Official comment
Hi Raoul_Dobal_PMG,
next to the approach mentioned by eibenĀ (thanks a lot Henning) using curly brackets to use multi line code you could also use the single line place holder notation starting with an = symbol -> [[= your JS code]]
For Number and also date formatting I often use the .toLocaleString function. Therefore you can use the following placeholder in your word template:
[[=[[NumberField]].toLocaleString("de-CH")]]
or if you need to pass other parameters as in the documentation below:
[[=[[NumberField]].toLocaleString("de-CH", { minimumFractionDigits: 2, maximumFractionDigits:2 })]]
Number: https://www.w3schools.com/jsref/jsref_tolocalestring_number.asp
Date: https://www.w3schools.com/jsref/jsref_tolocalestring.asp
-
Assuming you have a field called "MyNumberField" you could try something like this:
[[{ return new Intl.NumberFormat('de-CH').format([[MyNumberField]]) }]]
0 -
Thank you very much - both work. My word files now look much nicer.
0
Please sign in to leave a comment.
Comments
3 comments