Activity › Forums › Salesforce® Discussions › How to convert the String format decimal into a currency format in Salesforce Apex?

  • How to convert the String format decimal into a currency format in Salesforce Apex?

    Posted by Mohit on September 20, 2016 at 2:50 PM

    Hi All,

    How to convert the String format decimal into a currency format in apex?

    To concise function that formats a (String) decimal into a currency format in Apex.

    Please give suggestions.

     

    Parul replied 8 years ago 3 Members · 2 Replies
  • 2 Replies
  • Tanu

    Member
    September 21, 2016 at 7:46 AM

    Hello Mohit,

    Currency format of different countries are different,so we assume here "1,000.00" as currency format because in most of English countries this currency format is used.Let's try this code-

    String i='2050066.50';
    String s = ( Decimal.valueOf(i==null||i.trim()==''?'0':i).setScale(2) + 0.001 ).format();
    String p = s.substring(0,s.length()-1);
    System.debug(p);

  • [adinserter block='9']
  • Parul

    Member
    September 28, 2018 at 7:24 PM

    Hi

    public static String currency(String i) {
    String s = ( Decimal.valueOf(i==null||i.trim()==”?’0′:i).setScale(2) + 0.001 ).format();
    return s.substring(0,s.length()-1);
    }

    Hope it may help

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos