Click here to Skip to main content
14,698,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have amount field in database which is to be displayed in textbox. Now what i want is that it should contain only 2 digits after decimal point. how can i format this??
Updated 18-Dec-19 7:57am

Use ToString() overload where you can specify a format. So it will be like -
decimalValue.ToString ("#.##");

Hope this helps!
Member 8589824 10-Apr-12 4:39am
what should i write in place of #.##?
Ankur\m/ 10-Apr-12 4:51am
Don't replace that with anything. Copy it as it is.
VJ Reddy 10-Apr-12 4:56am
Good answer. +5
vino2012 10-Apr-12 6:35am
'#' means number format....
The solution 1 given by Ankur is good.
I want to add that if you want to force 0 to be displayed when there are no numbers after the decimal point and also to display a comma separator, the following format can be used
TextBox1.Text = Amount.ToString("#,0.00");
//The format will be
//3 ->  3.00
//3.4 ->  3.40
//.5 -> 0.50
//4594.3 -> 4,594.30
Ankur\m/ 10-Apr-12 5:02am
I missed that part, thanks for pointing out.
VJ Reddy 10-Apr-12 5:26am
Thank you.
decimalValue.ToString ("N2");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900