The format method automatically does the commas and periods or visa versa (depending on whether your profile is in the US or elsewhere)

Assuming the $ sign applies to all cases in your org you can simply use

Decimal input = 2000;
String output = '$' + String.valueOf(input.format());

Note the String.valueOf(). This is required because the input variable is defined as a Decimal.

Edit: I noticed a bug with the Decimal.format() method where it will not show any numbers past the decimal point if there are only zeros there, ex. $100.00. To solve this I came up with this method.

private String getCents(Decimal x){
    String y = String.valueOf(x);
    String z = '.';
    if(y.contains(',')) z = ',';
    y = y.substring(0, y.indexOf(z));
    if(x - Decimal.valueOf(y) == 0)
        return String.valueOf(x.format()) + z + '00';
    else return String.valueOf(x.format());
}

Then to update the example above, it would be:

Decimal input = 2000;
String output = '$' + getCents(input);
Answer from John Watson on Stack Exchange
Discussions

apex - Function to convert String to Decimal value? - Salesforce Stack Exchange
What part of this are you actually having trouble with? Are there any examples that aren't working? The documentation is pretty clear on what you can do with Decimals/Integers/Strings. ... Nick thanx for comment. i wanted to check is string is having Numeric value or Decimal value. More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
December 17, 2015
class - Convert Number to Words in apex salesforce - Stack Overflow
Below apex code can be used to convert number (currency) into words. This code can be used in triggers,visualforce pages to convert any number/currency field value in words and stored in any text f... More on stackoverflow.com
🌐 stackoverflow.com
Apex 5.1.4 Convert Number to Decimal - Stack Overflow
When a decimal number is entered in apex, it is displayed as 2.3, is there any simple code to convert it to 3 decimal places such as 2.300? More on stackoverflow.com
🌐 stackoverflow.com
Is there a way to check if a string is a number?
value = input() try: float(value) except ValueError: #somethin else: #something More on reddit.com
🌐 r/learnpython
36
30
August 5, 2024
🌐
S2 Labs
s2-labs.com › home › what is the rule of conversions in apex?
Rules of Conversion in Apex - S2 Labs training
In general, apex requires explicit conversion from one datatype to another; however, a few datatypes can be implicitly converted, such as variables of lower numeric type to higher types. For example, a variable of the Integer data type cannot be implicitly converted to a String.
Published   August 6, 2025
🌐
Concretio
concret.io › blog › using-decimal-class-with-strings-in-apex
Tip: Using Decimal class with Strings in Apex
February 10, 2026 - But it's Double class that is used in the v16 API, which has been upgraded to the Decimal class in later versions for more precision. So, to again get back to the same Double in Apex, we can change the code as shown below: Mock__c mock = [Select Counter__c from Mock__c where Name = 'Demo']; Double dblValue = mock.Counter__c .doubleValue(); String url = 'http://mycooldomain.com/'+ dblValue; System.debug ('Generated URL :' + url); Instead of directly appending any queried number field to the String, try storing it as a specific Type(Decimal) in a local variable.
🌐
Blogger
salesforcesource.blogspot.com › 2008 › 11 › utility-apex-class-to-convert-all-types.html
Salesforce : A Utility Apex Class to Convert All Types Into String
November 7, 2008 - ToString(Decimal, ScientificNotaion) ScientificNotaion is a Boolean value and if false is passed then the string will not have scientific notations.
Find elsewhere
🌐
Salesforcefaqs
salesforcefaqs.com › home › convert a string to decimal in salesforce apex
Convert a String to Decimal in Salesforce Apex
August 26, 2025 - In this Salesforce tutorial, I will explain how to convert a string to a decimal in Salesforce Apex.
🌐
Regardie
regardie.dev › post-3264
Apexのデータ型変換まとめ【Salesforce】 – Regardie's Salesforce Blog
Decimal → String · String convertedStr = String.valurOf(decimal); String → Decimal · Decimal convertedDec = decimal.valueOf(str); Decimal → Integer · Integer convertedInt = Integer.valueOf(decimal) Integer → Decimal · Decimal convertedDec = decimal.valueOf(int); Date → String ·
🌐
Stack Overflow
stackoverflow.com › questions › 40676675 › convert-number-to-words-in-apex-salesforce
class - Convert Number to Words in apex salesforce - Stack Overflow
Below apex code can be used to convert number (currency) into words. This code can be used in triggers,visualforce pages to convert any number/currency field value in words and stored in any text field.
🌐
Salesforce
trailhead.salesforce.com › trailblazer-community › feed › 0D54S00000A8435SAB
converting string to decimal in wrapper class - Trailhead
Skip to main content · Register now for TDX! Join the must-attend event to experience what’s next and learn how to build it
🌐
Forcetalks
forcetalks.com › home › salesforce® discussions › what is a concise function that formats a (string) decimal into a currency format in salesforce apex?
What is a concise function that formats a (String) decimal into a currency format in Salesforce Apex? - Forcetalks
November 14, 2017 - 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); ... The following should do the trick, with the assumption that your locale for currency formatting is correct. Edited to handle null being passed, and zero values after the decimal.
🌐
YouTube
youtube.com › roel van de paar
Salesforce: How do I convert a String to Decimal in Apex using a specific locale? - YouTube
Salesforce: How do I convert a String to Decimal in Apex using a specific locale?Helpful? Please support me on Patreon: https://www.patreon.com/roelvandepaa...
Published   April 1, 2021
Views   136
🌐
Stack Overflow
stackoverflow.com › questions › 47873137 › apex-5-1-4-convert-number-to-decimal
Apex 5.1.4 Convert Number to Decimal - Stack Overflow
oracle-apex · See similar questions with these tags. The Overflow Blog · To write secure code, be less gullible than your AI · The AI ick · Featured on Meta · We’re releasing our proactive anti-spam measure network-wide · Results of the October 2025 Community Asks Sprint: copy button for code... Opinion-based questions alpha experiment on Stack Overflow · 8 SQL How to convert a decimal to a string ·
🌐
Salesforce Developers
developer.salesforce.com › docs › atlas.en-us.apexcode.meta › apexcode › langCon_apex_rules_of_conversion.htm
Rules of Conversion | Apex Developer Guide | Salesforce Developers
In general, Apex requires you to explicitly convert one data type to another. For example, a variable of the Integer data type cannot be implicitly converted to a String. You must use the string.format method. However, a few data types can be implicitly converted, without using a method.
🌐
Greytrix
greytrix.com › blogs › salesforce › tag › convert-the-string-into-a-decimal-or-number
convert the string into a decimal or number Archives - Salesforce.com-Tips and Tricks
One common issue when integrating SF to any system is the “Illegal Assignment from String to Decimal” error, which occurs when string data from the other system is assigned to a numeric field in Salesforce. Integrating data between Salesforce and ERP (or any other system) can be complex, ...
🌐
Oracle
docs.oracle.com › en › database › oracle › apex › 24.2 › aexjs › apex.locale.html
apex.locale - JSDoc: Namespace
January 14, 2025 - The apex.locale namespace contains ... to a specific locale. For localizing text messages see apex.lang. ... Formats the given number in a compact, locale specific way. For example in the US English locale the number 123400 would be formatted as "123.4K" and 1234000 as "1.23M".
🌐
Forcetalks
forcetalks.com › home › 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? - Forcetalks
January 18, 2019 - Tagged: Currency Format, Decimal, Salesforce Apex, String ... To concise function that formats a (String) decimal into a currency format in Apex.
🌐
GRAX
grax.com › home › grax blog › beginner’s guide to data types in salesforce apex for salesforce admins & developers
Beginner’s Guide to Data Types in Salesforce Apex for Salesforce Admins
January 18, 2025 - Precision on regards to numerical values in Apex varies significantly based on the chosen data type. Knowledge of distinct differences between data types in this context is essential information for maintaining data accuracy in calculations. For example, here are the differences between 32-bit and 64-bit numbers, as well as a comparison between a 64-bit (Double) type and a Decimal type to showcase the potential accuracy loss: // 32-bit Integer (-2,147,483,648 to 2,147,483,647) ... String ...