Framework 1.0 and 1.1 differs in conversion of decimals to strings

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

Guest

Lets say i have a decimal value i the database e.g. 20.35. The field in the
database has a scale of 3. When I read this value into a DataSet and the
convert it to a string using ToString() the result is different depending on
if I'm using Framework 1.0 or 1.1. In 1.0 the result is 20.35 which is fine,
but in framework 1.1 the result is 20.350. What I have figured out is that
the behaviour of converting a System.Decimal to a string has changed in
framework 1.1. As we are upgrading a pretty big application from framework
1.0 to 1.1 this is quite a problem for us.

Does anyone know how to get back the old behaviour in framework 1.1, that is
if you have saved a decimal value of 20.35, that will be the value you get
after doing a ToString() without formatting info? We could use other
overridden methods of ToString but the problem is that we are also getting
xml from the dataset and it seems that the default ToString method is used
there as well to convert decimals to xml text, hence the same promblem
occurs.

Johan
 
I think this is a bug in 1.0 that they fixed in 1.1, as it is now correctly
interpreting the scale property. Try adjusting the scale to 2 - you can do
this either in the database, if you are using output parameters, you might
be able to set this by using setting the SqlParameter.Scale property.
 
Back
Top