Formatting Numbers in PDF as Currency~
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);
}
}
}
We'd love to hear your feedback.