0

For our multi-tier application, we use XmlConvert.ToString() to generate an xml.

This XML String is sent to a physical device for its configuration by our "configuration application".

Another application is responsible to connect the this physical device and has to check if the remote physical device has the same configuration.

We check that every field has the same String value.

We write the value with

stringValue = XmlConvert.ToString((decimal)objValue);

We don't have the same local between the two software, and it seems that it has effect:

We receive the decimal value 1. On one application (the configurator) with my custom locales(fr-CH), I've the following output: "1".

But on the other application, with the exact same code, we receive the output "1.0", making our verification failing.

I was thinking after a little research( here) that the XmlConvert.ToString was culture invariant). no?

In addition, I cannot configure any "culture" to use to serialize my decimal. What am I missing?

J4N
  • 19,480
  • 39
  • 187
  • 340
  • 1
    Are you absolutely *certain* that you receive 1 on both machines, rather than 1.0? They have different representations in `decimal`. – Jon Skeet Jan 10 '14 at 12:47
  • No, I'm not absolutely certain, I just know that when I hover te variable with the mouse in visual studio, I've `1` displayed in both case. Even if they have different representation, is there a way to ensure that they are written the same? – J4N Jan 10 '14 at 12:54

1 Answers1

0

I finally found more informations, thanks to the @Jon Skeet comment.

Due to decimals having the "precision" notion(didn't know that), I was receiving once "1.0", once "1"(in fact, the 1.0 was coming from the database, which I guess force some precision).

I found this to normalize my decimal, which works very nicely:

public static class DecimalExtensions
{
    public static Decimal Normalize(this Decimal value)
    {
        return value / 1.000000000000000000000000000000000m;
    }
}
J4N
  • 19,480
  • 39
  • 187
  • 340