Decimal with 2 decimal places

I need to get a Decimal into a format with 2 decimal places and without a currency sign (like $). I have this (where amount is Decimal):
string myString = (String.Format ("{0:.##}", this.amount));
decimal decimalRounded = Decimal.Parse(this.amount.ToString("0.00"));
return decimalRounded;

Open in new window

but I still get numbers like 1234.5, not 1234.50.
How can this be done?
Who is Participating?
Craig WagnerConnect With a Mentor Software ArchitectCommented:
You can't really format a "Decimal", you can only format it when you turn it into a string. When it is in its numeric form then 1234.5 is accurate. If you want to display that number as 1234.50 then you need to do what you're already doing, which is String.Format it.
decimal d = 1234.5678;
d = decimal.Round(d, 2);
Console.WriteLine("decimal variable d value: {0}", d); // Prints 1234.57
allelopathAuthor Commented:
The first line in the code snippet doesn't compile:
Cannot convert source type 'double' to target type 'decimal'
allelopathAuthor Commented:
I see what you are saying. So I created a getter to return a string:
public string AmountString
            string myString = (String.Format("{0:.##}", this.amount));
            return myString;
If the value has no decimal places, e.g. 1234, it returns 1234, not 1234.00
If it has 1 decimal place, e.g. 1234.1, it returns 1234.1, not 1234.10
allelopathAuthor Commented:
This works:
string myString = (String.Format("{0:0.00}", this.amount));
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.