0

I am having a requirement where I have to display amount coming from apex in Vietnamese format in VF page. As there are lots of amount and lots of calculation going behind it so I can't do it in Apex. Eg - 1234567 --> 1.234.567

Things I tried -

<apex:outputText value="{0, number, ###,###.##}">
                            <apex:param value="{!amount}" />
                        </apex:outputText>

It is giving me in 1,234,567 format. I tried ###.###.## but it is giving me invalid format. I also tried adding a script tag by using standard ne.toLocaleString('vi-VN') method and used document.write to add. eg :

<td><script>var amt =amt.toLocaleString('vi-VN');document.write(amt) </script></td>. But as I am generating pdf document.write is not working. It is working when I remove renderas = "pdf"

0

2 Answers 2

0

As per this documentation: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_outputText.htm

Currency formatting example

<!-- For this example to render properly, you must associate the Visualforce page
with a valid account record in the URL.
For example, if 001D000000IeChM is the account ID, the resulting URL should be:
https://Salesforce_instance/apex/myPage?id=001D000000IeChM
See the Visualforce Developer's Guide Quick Start Tutorial for more information. -->

<apex:page standardController="Account">
It is worth:
<apex:outputText value="{0, number, 000,000.00}">
       <apex:param value="{!Account.AnnualRevenue}" />
 </apex:outputText>
</apex:page>

The example above renders the following HTML:

It is worth: 500,000,000.00

So You can try to replace <apex:outputText value="{0, number, ###,###.##}"> With the <apex:outputText value="{0, number, 000,000.00}">.

3
0

I have investigated and found the following workaround. I have formatted the number into the Vietnam currency using the js.

VF page:

<apex:page>
    <script type="text/javascript">
    
    function formatNumber(number) {
        let num = new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(number);
        console.log(num);
        document.getElementById("demo").innerHTML = num;
    }
    
    </script>
    <body>
        <p id="demo"></p>
        <button onclick = "formatNumber(123456789)"> click me !</button> 
    </body>
</apex:page>

Output: enter image description here

You can modify the code to pass the dynamic value to the function.

2
  • I need to create a pdf file. Not a vf page Jul 13, 2023 at 11:17
  • PDF rendering doesn’t support JavaScript-rendered content. Jul 13, 2023 at 11:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .