September 22, 2014

Decimal to Currency format using apex in Salesforce

format() can be used.

Sample Code:

Decimal a = 14862.00;
system.debug('Currency is ' + (a.format().contains('.')?a.format():(a.format()+'.00')));

a = 14862.05;
system.debug('Currency is ' + (a.format().contains('.')?a.format():(a.format()+'.00')));

Output:



3 comments:

  1. Does not work for Decimal 12345.50
    Shows 12,345.5

    ReplyDelete
  2. can't believe apex still does not have this functionality. jeez

    ReplyDelete