Extra zeros when showing decimal value from database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using framework 1.1 and SQLServer 2000. When I read decimal values from
the database into a DataSet and the show the value i e.g. a TextBox, an extra
zero is added to the end of the value. If the value is 20.35 in the database,
20.350 is shown in the TextBox. The field in the database is a decimal of
length 9, precision 18 and scale 3. Hence there is room for 3 decimals but I
have only two in the value I have stored. It seems like the framework always
fills out with zeros until the number of decimals set in scale always is
shown. If you look at the value in the watch window it is 20.35 but it seems
like the extra zero is added when converting the value to a String using
ToString().

Is there any way of just showing exactly the number of decimals I hav saved
in the database and get rid of this extra zero adding?

Thanks for help
Johan
 
You can use the overloaded method of ToString that received the format. For
example:

Dim myNumber As Double = 12.3568

MessageBox.Show(myNumber.ToString("0.00"))

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
Thanks Carlos,

The problem is that this is a global system with many installations and it
would be quite costly for us to do such a change. The problem is also that
some customers want a specific number of decimals. The utlimate solution for
us would to control the number of decimals by using cultural settings but
can't get it to work i all cases. For example, when we generate an XML file
from a dataset the same problem occur for the decimal values in the XML file.
Somehow the xml-generator uses the default conversion of decimals to strings
which will end up with 3 decimals. Do you have any ideas of how to solve that?

Johan
 
Back
Top