Reputation: 1
i want to display my price value like after decimal point only two digits to display. i try this.
lblDiscount.Text = string.Format("{0:c} ", Convert.ToString(sDis));
but it is displaying three digits after point. can you please tell me how to format price
Upvotes: 0
Views: 275
Reputation: 569
assuming sDis is a decimal value, you do not need to use Convert.ToString() on it within the string.Format() call.
I would replace what you have with:
lblDiscount.Text = string.Format("{0:C2}", sDis);
or even just
lblDiscount.Text = sDis.ToString("C2");
Upvotes: 0
Reputation: 12417
From Standard Numeric Format Strings on MSDN:
decimal value = 123.456m;
Console.WriteLine("Your account balance is {0:C2}.", value);
// Displays "Your account balance is $123.46."
Upvotes: 3
Reputation: 62127
Reqad up on:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
and then follow the links until you reach custom formatting.
Upvotes: 0
Reputation: 13823
I am not sure of the type of sDis, but try using -
lblDiscount.Text = sDis.ToString("#0.00");
or you can try using -
lblDiscount.Text = Convert.ToDouble(sDis).ToString("#0.00");
Upvotes: 0