Currency format Javascript ES5

Hello,

How can I format currency in portuguese format (R$ 3.999.222,11) where decimal separator is comma, not point.

I tried using locale:'pt-br' but it didn't work. At the end of this thread, I pasted a SS.

Another question, how could I show number in M or K format, like R$ 3M for 3 million, or R$ 5K for 5 thousand?

Thank you

I'm using javascript ES5 (without typescript).

Maikel



4 Replies 1 reply marked as answer

SM Srihari Muthukaruppan Syncfusion Team July 9, 2020 01:18 PM UTC

Hi Maikel, 
  
Greetings from Syncfusion. 
  
We have analyzed your query. From that, we would like to let you know that we can achieve your requirement using localization and axisLabelRender event property in the chart. Based on your requirement we have prepared a sample for your reference. Please find the below sample, code snippet, and screenshot. 
  
 
Code Snippet:  
 
import * as currencies from './currencies.json';
import * as cagregorian from './ca-gregorian.json';
import * as numbers from './numbers.json';
import * as timeZoneNames from './timeZoneNames.json';

ej.base.loadCldr(currencies, cagregorian, numbers, timeZoneNames);
ej.base.setCulture('pt');
ej.base.setCurrencyCode('BRL');
 

 
 
let chart: Chart = new Chart({
        useGroupingSeparator: true,
        primaryYAxis:
        {
            title: 'Profit ($)',
            rangePadding: 'None',
            lineStyle : { width: 0 },
            majorTickLines : {width : 0},
            labelFormat: 'c2',
        },
        axisLabelRender: (args) => {
          if (args.axis.name === 'primaryYAxis') {
                  var number = args.text.replace(/,/g , "__COMMA__").replace(/\./g, ',').replace(/__COMMA__/g, '.');
                  var text = number.split('R$')[1];
                  var value = parseInt(text.replace( /,/g, "" ));
                  if(value > 0 && value < 10000) {
                    args.text = 'R$'+(value/1000)+'K';
                  } else {
                    args.text = 'R$'+(value / 1000000)+ 'M';
                  }
              }
        }
// add your additional code here
});
 
  
Screenshot: 

 
Let us know if you have any concerns. 

 
Regards, 
Srihari M


Marked as answer

MC Maikel Cordeiro July 14, 2020 01:22 AM UTC

Hi,

I'm sorry for not replying to this thread before, but I follow your suggestion, and with some changes, it worked perfectly.

Thank you so much!

You can see it working here in the picture. Positive and negative values; K and M values; X-axis as well. And value format I handled in the tooltip screen.

Best Regards.

Maikel




SM Srihari Muthukaruppan Syncfusion Team July 14, 2020 06:07 AM UTC

Hi Maikel 
  
Most welcome. Kindly get in touch with us, if you require further assistance. We are always happy in assisting you.   
   
Thanks,   
Srihari M 




MC Maikel Cordeiro July 14, 2020 01:26 PM UTC

Thank you so much!

Syncfusion support team is awesome!

Best Regards.

Loader.
Up arrow icon