I am currently using the visual force component to get the grand total of my pageblocktable column as referred too in this question 'To achieve Grand total for the retrieved column in a datatable generated using Soql' Please and help will be greatly appreciated. Thanks! Here is the total. How can I format this in to dollar amount? Nothing is working, please advise.
-
Jonathan, what precisely isn't working ? Maybe we can better understand if you show us your code and current progress or attempts.– Samuel De RyckeCommented Jan 29, 2015 at 15:52
-
Is this better?– Jonathan BrooksCommented Jan 29, 2015 at 21:21
-
This is the code it is all visual force.– Jonathan BrooksCommented Jan 30, 2015 at 14:23
3 Answers
Below is the code which could help you in formatting total value :
<script>
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
// Here we will set the generated subtotals to the footer cells
document.getElementsByClassName('t4')[0].innerHTML
= '$ '+numberWithCommas({!total4});
</script>
This will allow you to maintain comma in between total value. Example Total: 397423.66 will be displayed as 'Total: $ 397,423.66'
-
hot diggidy daym! Thats some sweet code right there! All those escapes n stuff. Impressive! Commented Aug 19, 2015 at 6:37
Pretty sure you need to add an apex:param
between the apex:outputText
tags that contains the value you wish to format.
<apex:outputText value"{0,number,$###,###,##0.00}">
Total
<apex:param value="{!total4}" />
</apex:outputText>
-
I tried this and it did not work because total4 is an apex variable but I got it figured out the Javascript just will not show when it is in being rendered as a PDF now. Commented Jan 30, 2015 at 14:24
If you are setting the GrandTotal using Javascript, why not add the $ during that point?
document.getElementsByClassName('t4')[0].innerHTML = '${!total4}';