Hi everyone!
How can I change decimal places in pivot table element?
Thanks!
Hi everyone!
How can I change decimal places in pivot table element?
Thanks!
I would be interested in knowing that as well.
Me too!! I just want to format numbers to an integer - can’t be too much to ask?
Hi,
I just got an email from Moe asking if I can get more involved in the community. I’m grateful to tada and am excited to pay it forward. Tag me if you need some special java code.
I encountered a similar annoyance in the past and successfully resolved it through the implementation of a rather rudimentary code.
I used AI to ask it to add context and notes to the code. Change values as per your requirements.
TB.render('component_3', function(data) {
// Get the table element by its id
var table = document.getElementById("x_element_page_22_3");
// Get all the table cells
var cells = table.getElementsByTagName("td");
// Loop through each cell and format the numeric values
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
var value = cell.innerHTML;
// Check if the value is a number
if (!isNaN(value)) {
// Format the number with decimal places and periods
var formattedValue = parseFloat(value).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
// Update the cell with the formatted value
cell.innerHTML = formattedValue;
}
}
});
Many thanks for your reply David! I tried the javascript above and modified it with my element ids, but it doesn’t change the decimal places?
TB.render(‘component_44’, function(data) {
// Get the table element by its id
var table = document.getElementById("x_element_page_31_44");
// Get all the table cells
var cells = table.getElementsByTagName("td");
// Loop through each cell and format the numeric values
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
var value = cell.innerHTML;
// Check if the value is a number
if (!isNaN(value)) {
// Format the number with decimal places and periods
var formattedValue = parseFloat(value).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
// Update the cell with the formatted value
cell.innerHTML = formattedValue;
}
}
});
This is an old thread but thought I would update since it might come in handy for someone else. I had the same issue, just needed full integers in a pivot table not decimals. Used the code above and changed the .toFixed(2) to a zero and it worked in the bottom line (Total row) of the pivot table but not the other rows. Plugged the code into chatgpt and was able to eventually get it to work for all rows. Code below will remove digits after the decimal, adjust how many digits you want changed the value after .toFixed:
TB.render('component_30', function(data) {
// Get the table element by its id
var table = document.getElementById("x_element_page_86_30");
// Get all the table cells
var cells = table.getElementsByTagName("td");
// Loop through each cell and format the numeric values
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
var value = cell.textContent.trim(); // Use textContent to get raw text and trim spaces
// Check if the value is a number
if (!isNaN(value) && value !== "") { // Ensure value is numeric and not empty
// Format the number with decimal places and periods
var formattedValue = parseFloat(value).toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
// Update the cell with the formatted value
cell.textContent = formattedValue; // Use textContent to avoid adding unexpected HTML
}
}
});