I need to get a money value from the database and show it like 5.89 not like 5.8900. Any tips?
txtStartingBid.Text = (string)auhelper.getScaler(string.Format("SELECT Auctions.StartingBidPrice FROM Auctions WHERE Auctions.ID={0}", auctionId)).ToString();
warrenkc2
Member
71 Points
75 Posts
Format to 2 decimal places.
Apr 24, 2012 04:42 AM|LINK
I need to get a money value from the database and show it like 5.89 not like 5.8900. Any tips?
txtStartingBid.Text = (string)auhelper.getScaler(string.Format("SELECT Auctions.StartingBidPrice FROM Auctions WHERE Auctions.ID={0}", auctionId)).ToString();decimal
narasappa
Participant
960 Points
458 Posts
Re: Format to 2 decimal places.
Apr 24, 2012 04:48 AM|LINK
just use
double amt1=59.8888;
double amt=Math.Round(amt1,2);
decimal
ravi.jadiyannavar@gmail.com
Pls Mark This Post As Answer If it Helps U..
Thanku
poojajoon
Member
228 Points
52 Posts
Re: Format to 2 decimal places.
Apr 24, 2012 04:54 AM|LINK
hey
try this
SqlConnection conn=ConfigurationManager.ConnectionStrings["con"].ConnectionString;
SqlCommand cmd=new SqlCommand("SELECT Auctions.StartingBidPrice FROM Auctions WHERE Auctions.ID={0}",conn);
Double price=Convert.ToDouble(cmd.ExecuteScalar());
price=Math.Round(price,2)
txtStartingBid.Text =Convert.ToString(price);
Hope this will help you.
nbsamurai
Member
592 Points
220 Posts
Re: Format to 2 decimal places.
Apr 24, 2012 05:06 AM|LINK
txtStartingBid.Text = string.Format("{0:N2}%", x); // where x = StartingBidPrice
decimal
warrenkc2
Member
71 Points
75 Posts
Re: Format to 2 decimal places.
Apr 24, 2012 05:09 AM|LINK
Thanks!