How to Display an Integer in Hexadecimal, Decimal and Scientific notations using C# (.NET)
Composite formatting can be used to format the output into various forms as shown below
private static void ListNumbersAsHexOctSciFormat()
{
try
{
Console.WriteLine("Decimal Hexadecimal Exponential (Scientific)");
for (int i = 1; i <>
{
Console.WriteLine("{0:D} \t{0:X} \t{0:E}",i );
}
}
catch (FormatException dEX)
{
Console.WriteLine("Formatting Exception" + dEX.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
To convert a string use String.Format method
string S1 = String.Format("{0:X}", i);
Formatting Strings in C#, Formatted Output in C#, C# Convert Decimal to Hexadecimal, Decimal to Hexadecimal Conversion using C#, Integer to Scientific notation using C#, C# Scientific notations, C# Integer to Hexadecimal, C# Integer to Decimal, C# Integer to Exponential notations, .NET Integer to Decimal, .NET Integer to Exponential notations
No comments:
Post a Comment