Decimal into string conversion shows different decimal values in different windows systems

  • Thread starter Thread starter En-coder
  • Start date Start date
E

En-coder

Guest
I have a c# code running in .net framework 2.0 that when converting a decimal into a string to be printed in a file produces different outputs in different Windows OS.

I have checked already that both system reginal settings are exactly the same, same language, same numer format etc.

My code looks like this

object o = dr.GetValue(dr.GetOrdinal(cCol.ColumnName));
string value = Convert.ToString(o);


It is getting a value from a database and the object is of type Decimal (o.GetType()==typeof(Decimal) evaluates to true)

The problem is that when this program runs in .net Framework 2.0 but in a windows 2000 server the output is not the same as running in .net framework 2.0 in windows 10.

For example for the value 2016

Windows 2000 output: "2016"

Windows 10 output: "2016.00"

I have tried the following

string value = ((Decimal)o).ToString("0.##"));

Then the output is the same for the value 2016. However, and here is where it gets tricky, if the value is let's say 2016.6, the output with this new method is:

Windows 2000 output: "2016.60"

Windows 10 output : "2016.6"

So there is no way I can't get it to output the same in both systems.

What can be the source of the problem? Is there any way I can get in windows 10 the same output as Windows 2000?

Thank you

Continue reading...
 
Back
Top