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 › 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.
🌐
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.
🌐
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#
The ':' in a format string is the seperator between the value placeholder and the value’s format. So in the below example the first placeholder '{0}' is just going to display the first parameter which is the day of the week – note there is no formatting here, and the second placeholder '{1:t}' is going to hold the second parameter which is the time, and will also format it using the value 't' which stands for Short time pattern.
🌐
C# Examples
csharp-examples.net › string-format-double
String Format for Double [C#]
// 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.
🌐
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
Find elsewhere
🌐
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).
🌐
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.
🌐
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.
🌐
Appeon Community
community.appeon.com › qna › q-a › decimal-to-formatted-string
Decimal to Formatted String - Appeon Community
I need to convert a decimal number in a variable "1234.22" into a string and need it in the format "1,234.22" (money) such that I can display it on a text field when the program is run. I am unsure of how I can approach this..
🌐
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, ...
🌐
Hubitat
community.hubitat.com › 📐 rule machine® › rules examples
[ How to ] Format Decimal to String ie: "#.##" - Rules Examples - Hubitat
March 26, 2024 - This rule will format any decimal number to a string with fixed 2 decimal places. ie: #,## decimal number 2.1 = string "2.10" See comments in rule & note local variables in the rule.