function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hithesh SaicharanHithesh Saicharan 

Add comma in currency in APEX

I want to convert this decimal value 10600.05 into 10,600 in APEX. and I am trying with this code
 
Decimal rA = 10600.86;
Integer Intval=ra.intvalue();
List<String> args = new String[]{'0','number','###,###,###,###'};
String s = String.format(Intval.format(), args);


But I am always getting 

10 600 as output. Comma is not coming in output. I want this only in APEX and in VF page. Any help please?
AnkaiahAnkaiah (Salesforce Developers) 
Hi Hithesh,

try with below code in dev console.
Decimal rA = 10600.86;
Integer Intval=ra.intvalue();
system.debug('Intval=='+Intval.format());

Refer the below link.
​​​​​​https://salesforce.stackexchange.com/questions/118624/how-to-format-number-with-comma-in-apex
If this helps, Please mark it as best answer.

Thanks!!
Hithesh SaicharanHithesh Saicharan
Its also giving output as 10 600 but i need it as 10,600
AnkaiahAnkaiah (Salesforce Developers) 
Refer the below link and try

https://salesforce.stackexchange.com/questions/118624/how-to-format-number-with-comma-in-apex

If not working then provide the VF page and apex class.

Thanks!!
Tushar JadavTushar Jadav
Hello,

try this,
 
Decimal rA = 10600.86;
List<String> args = new String[]{'0','number','###,###,##0.00'};
String s = String.format(rA.format(), args);
System.debug(s);

It works look at the screenshot.
User-added image
Tushar JadavTushar Jadav
Hello,

try this: 
 
Decimal rA = 10600.86;
Integer Intval=rA.intvalue();
List<String> args = new String[]{'0','number','###,###,###,###'};
String s = String.format(Intval.format(), args);
System.debug(s);
It works look at the screenshot.
User-added image