Format Textbox with Floating Decimal Point

R

Randy

I'm sure that this has been posted before, but I can't find it.
Please accept my apologies for any redundancy.

I have a textbox that contains numbers pulled from a SQL database
column. These the datatype in the db is set to "decimal(18, 4)", so
the number is stored with 4 decimal places, although they could all be
zeros. When I pull these numbers into the textbox, I want to display
only the significant digits (i.e. drop any trailing zeros). For
example, if the db contains a number of "5.1200", I want to display
"5.12". If the db showed "5.1234", I want to display "5.1234". If it
contains "5.0000", I want to display "5".

I can change the datatype of the SQL table if that will help.

Thanks,
Randy
 
G

Guest

Randy,

I have not tried this, but pretty sure it should work:
myTextBox.Text = CType(myDatabaseField, Single).ToString()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top