Sorry for reactivating this question, but I didn't find the right answer here.

In formatting numbers you can use 0 as a mandatory place and # as an optional place.

So:

// just two decimal places
String.Format("{0:0.##}", 123.4567);      // "123.46"
String.Format("{0:0.##}", 123.4);         // "123.4"
String.Format("{0:0.##}", 123.0);         // "123"

You can also combine 0 with #.

String.Format("{0:0.0#}", 123.4567)       // "123.46"
String.Format("{0:0.0#}", 123.4)          // "123.4"
String.Format("{0:0.0#}", 123.0)          // "123.0"

For this formating method is always used CurrentCulture. For some Cultures . will be changed to ,.

Answer to original question:

The simpliest solution comes from @Andrew (here). So I personally would use something like this:

var number = 123.46;
number.ToString(number % 1 == 0 ? "0" : "0.00");
Answer from Gh61 on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › standard › base-types › standard-numeric-format-strings
Standard numeric format strings - .NET | Microsoft Learn
The exponential ("E") format specifier converts a number to a string of the form "-d.ddd…E+ddd" or "-d.ddd…e+ddd", where each "d" indicates a digit (0-9). The string starts with a minus sign if the number is negative. Exactly one digit always precedes the decimal point.
Discussions

c# - Converting Decimal to string with non-default format - Stack Overflow
I need to convert decimal to string, in this rulers: 120.00 - "120" 120.01 - "120.01" 120.50 - "120.50" More on stackoverflow.com
🌐 stackoverflow.com
String Format to show decimal up to 2 places
Hi - I have a message box at the end of a workflow to display total elapsed time but I want to truncate the milliseconds. TimerObj - is the variable I assigned for Start & Stop Timer. In the expression builder I used st… More on forum.uipath.com
🌐 forum.uipath.com
1
0
December 31, 2022
.net - decimal to string conversion in C# - Stack Overflow
How can I convert a list of decimal values to strings such that: No decimal point is shown if the value is an integer Otherwise, the number is formatted to a minimum of two decimal places For examp... More on stackoverflow.com
🌐 stackoverflow.com
How to format a decimal into a string?
hi!... new to navision here... in C/AL code, how will i format a number with data type of decimal into a string?... More on forum.mibuso.com
🌐 forum.mibuso.com
September 9, 2004
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.decimal.tostring
Decimal.ToString Method (System) | Microsoft Learn
In converting the numeric values to strings, the example uses the formatting conventions of the en-US culture. decimal value = 16325.62m; string specifier; // Use standard numeric format specifiers.
🌐
GeeksforGeeks
geeksforgeeks.org › c# › c-sharp-decimal-tostring-method-set-1
C# | Decimal.ToString Method | Set -1 - GeeksforGeeks
July 11, 2025 - Example 1: ... // C# program to demonstrate the // Decimal.ToString(String) Method using System; class GFG { // Main Method public static void Main() { try { // Declaring and initializing value decimal value = 16325.62m; // Declaring and ...
Top answer
1 of 4
33

You can use the decimal.ToString override to specify a formatting.

decimal amount = 120.00m;
string str = amount.ToString("0.00");

This can also be used when using String.Format.

Console.WriteLine("{0:0.00}", amount); 

In the case of your first rule, it cannot be done on one line.

decimal amount = 120.00m;
string str = amount.ToString("0.00").Replace(".00", String.Empty);
2 of 4
8

There are different overloads for decimal.ToString based on what formatting you want.

Example

decimal d = 5.00
Console.WriteLine(d.ToString("C")); // for currency

See below for other overloads... specifier is what you put into the ToString(specifier)

MSDN Documentation on Decimal.ToString

decimal value = 16325.62m; string specifier;

// Use standard numeric format specifiers.
specifier = "G";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays:    G: 16325.62
specifier = "C";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays:    C: $16,325.62
specifier = "E04";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays:    E04: 1.6326E+004
specifier = "F";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays:    F: 16325.62
specifier = "N";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays:    N: 16,325.62
specifier = "P";
Console.WriteLine("{0}: {1}", specifier, (value/10000).ToString(specifier));
// Displays:    P: 163.26 %

// Use custom numeric format specifiers.
specifier = "0,0.000";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays:    0,0.000: 16,325.620
specifier = "#,#.00#;(#,#.00#)";
Console.WriteLine("{0}: {1}", specifier, (value*-1).ToString(specifier));
// Displays:    #,#.00#;(#,#.00#): (16,325.62)
🌐
Dave on C#
daveoncsharp.com › 2009 › 09 › formatting-decimals-in-csharp
Formatting Decimals in C# - Dave on C-Sharp
In this post I am going to show you a few different ways how you can format a decimal number (float, double, or decimal). To format your numbers to a maximum of two decimal places use the format string {0:0.##} as shown in the below example: string.Format(“{0:0.##}”, 256.583); // “256.58” ...
🌐
UiPath Community
forum.uipath.com › help › studiox
String Format to show decimal up to 2 places - StudioX - UiPath Community Forum
December 31, 2022 - Hi - I have a message box at the end of a workflow to display total elapsed time but I want to truncate the milliseconds. TimerObj - is the variable I assigned for Start & Stop Timer. In the expression builder I used string.format(“{0:00}”,TimerObj.Elapsed.TotalMinutes.ToString).
Find elsewhere
🌐
C# Examples
csharp-examples.net › string-format-double
String Format for Double [C#] - C# Examples
// just two decimal places String.Format("{0:0.00}", 123.4567); // "123.46" String.Format("{0:0.00}", 123.4); // "123.40" String.Format("{0:0.00}", 123.0); // "123.00" Next example formats double to string with floating number of decimal places.
🌐
Online String Tools
onlinestringtools.com › convert-decimal-to-string
Convert Decimal to a String – Online String Tools
Free online decimal to string converter. Just load your decimal and it will automatically get converted to a string. There are no intrusive ads, popups or nonsense, just a decimal to string converter. Load a decimal, get a string.
🌐
mibuso.com
forum.mibuso.com › navision attain
How to format a decimal into a string? — mibuso.com
September 9, 2004 - 1,234.56), and if so, should the 'grouping symbol' follow the convention for the user's locale, or do you require a specific character? So, you need to experiment a little. Start with: MyString := FORMAT(MyDecimal); If this doesn't give you the right number of decimal places, try
🌐
Phrase
phrase.com › home › resources › blog › how do i convert a decimal to a string with thousands separators?
How Do I Convert a Decimal to a String with Thousands Separators?
January 23, 2025 - We have a number as a double or ... to take care of thousands separators; so 1000000 is formatted to the string "1,000,000", in the US English (en-US) locale, for example. Let’s take a look at how to convert a decimal to a string....
🌐
PhraseFix
phrasefix.com › tools › decimal-to-string
Decimal to String Converter - PhraseFix
Free online tool that converts decimal numbers to string. Simply enter the decimal and the online tool will convert it into text.
🌐
Oracle
docs.oracle.com › javase › tutorial › i18n › format › decimalFormat.html
Customizing Formats (The Java™ Tutorials > Internationalization > Formatting)
You can use the DecimalFormat class to format decimal numbers into locale-specific strings. This class allows you to control the display of leading and trailing zeros, prefixes and suffixes, grouping (thousands) separators, and the decimal separator. If you want to change formatting symbols, ...