Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set decimal places in typed dataset?

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
0
0
US
I have a typed dataset that gets filled from a SQL table with money datatype fields. When I bind to my text boxes I get 4 decimal places. What's the best way to show only 2 decimal places? Thanks.
 

Dim MyPos As Double = 19.95
Dim MyString As String = MyPos.ToString("$#,##0.00;($#,##0.00);Zero")
...yields $19.95

Also, one might use the DataFormatString {0:C} for currency, for example, in a datagrid:

<asp:BoundColumn
HeaderText=&quot;Price&quot;
DataField=&quot;CurrencyValue&quot;
DataFormatString=&quot;{0:c}&quot;>
</asp:BoundColumn>

..and there are surely other paths one could take. For example, see the discussion at thread855-712598

Post back if any troubles, someone else may drop by and post something along these lines.
 
Hmm... DataFormatString isn't available in a Text Box. Also, I don't want to have to run code on every value returned from the database.
 
qwert: Good point - it seems, on first glance, that when the data is bound (e.g., if you are doing simple binding), you can format on binding...

...however, I am not familiar with using a Format string within a textbox - something tells me that it can be done; but the only examples I can find (not at home now, so no library in front of me) is to format on binding.

Good question though. I suspect you could use JavaScript to accomplish this. It'll be interesting to see how this works out.
 
Hmm... I design time DataBind the textbox with a typed dataset, and I didn't notice before, but with VS 2k3 you have a drop down box that allows you to specify formatting. Thanks for the tips tho.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top