Format Textbox with Floating Decimal Point

  • Thread starter Thread starter Randy
  • Start date Start date
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
 
Randy,

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