asp.net - Issue with String.Format output -


i trying display @ 2 decimal places in smallcurrency field being pulled sql database. can see in image below using format specifiers limit number of decimal places rendered controls on screen.

code sets fields on page

the markup text controls

however can see in image below fields displaying 4 decimal places (despite database containing records holding 2 decimal places). have attempted variety of different format specifiers omitting string.format has had no effect.

am missing obvious here or strange happening work?

the controls rendered on page

you shouldn't call tostring() on value inside format. counteracts format completely, turning value string (with 4 decimal places in case), , ignores other formating.

if want leave textbox blank (as per comments) when field empty, surround assignment if statement.

if productinformation.rows(0)("monthlyprice") isnot dbnull.value     me.txtmonthlyprice.text = string.format("{0:0.##}", productinformation.rows(0)("monthlyprice")) else     me.txtmonthlyprice.text = "" end if 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -