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

  • 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);

  • 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