{%Pragmatic Coding%} Tips and tricks for software developers.

15Sep/120

How To: Format Decimal.ToString() in C#

Today I have spent some time to find out how correctly convert and format decimal number to string representation with 2 decimal digits. And here is what I found and learned I want to share it with you my friend.
I'll give you several C# examples that shows how to format float numbers to string in C#. You can use static method String.Format or instance methods double.ToString and float.ToString.

Digits after decimal point

This example formats double to string with fixed number of decimal places. For two decimal places use pattern „0.00“. If a float number has less decimal places, the rest digits on the right will be zeroes. If it has more decimal places, the number will be rounded.

Read the full article...