开发者

Formatting price

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. c开发者_如何学Can you please tell me how to format price


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."


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");


Reqad up on:

http://msdn.microsoft.com/en-us/library/az4se3k1.aspx

and then follow the links until you reach custom formatting.


if sDis is double then

lblDiscount.Text = sDis.ToString("#.##");


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜