Converting Decimal to String:
Converting a decimal to a string in C# is simple and can be achieved using the ToString
method. This method is available for all numeric data types in C#, allowing us to convert decimal values to their string representation.
using System;
class Program
{
static void Main()
{
// Define a decimal number
decimal myDecimal = 135.51;
// Convert decimal to string
string myString = myDecimal.ToString();
// Display the result
Console.WriteLine("Decimal Value: " + myDecimal);
Console.WriteLine("String Representation: " + myString);
}
}
In this above program, we have declared a decimal variable (myDecimal
) and then used the ToString
method to convert it to a string (myString
).
Output:
Decimal Value: 135.51
String Representation: 135.51
Comments (0)