Format numbers as currency in a PDF
If you're working in a details component on PDF pages and want to ensure a number is formatted as a currency field instead of number, here's a basic…
- Not yet re-checked
- Classic builder
Moved from our previous help site and not yet re-checked against the current product. Last edited Sep 20, 2024.
If you're working in a details component on PDF pages and want to ensure a number is formatted as a currency field instead of number, here's a basic guide to doing this.
In the details component, open every field that should be formatted as a currency and add a class of 'currency'
Then add this to Javascript
window.onload = function() {
var elements = document.querySelectorAll('.currency .t-pdf-details-value');
for (var i in elements) {
var element = elements[i];
// Parse the text content to a number
var number = parseFloat(element.textContent);
// If the text content is a valid number, format it as currency
if (!isNaN(number)) {
// Format the number as currency and update the text content
element.textContent = "$" + number.toFixed(2);
}
}
} Was this page helpful?
Something wrong or missing on this page? Tell us.