1

私は次のものを持っています:

 private static string someValue = "0.1";

計算を行うには、これを double に変換する必要があります。ドイツのシステムでは、0.1 ではなく 0.1 として変換されます。0.1 が必要です。私は次のことを試しました:

double d = Convert.ToDouble(s_valueDeadband10Percent, CultureInfo.InvariantCulture.NumberFormat); // still getting 0,1

double d = Convert.ToDouble(s_valueDeadband10Percent, CultureInfo.InvariantCulture); // still getting 0,1

何か案は ?

4

2 に答える 2

5

On a German system I get the conversion as 0,1 rather than 0.1, I need it as 0.1.

No, you don't get either of those. You get a double value which is approximately a tenth. A double value isn't a textual "thing" at all. It can be converted to text, but that's a different operation. You need to find where that operation is, and change that to use CultureInfo.InvariantCulture, if you really want a text value. But if you can get away without the conversion back to a string at all, that would be even better.

Of course, if possible, you should change your static variable to be a double to start with:

private static double someValue = 0.1;

That way you can avoid parsing, too.

于 2013-05-16T21:22:40.780 に答える
2

double の文字列表現と実際の値を混同していると思います。

コードは文字列 "0.1" を 0.1d に適切に変換する必要があります。(デバッガー、コンソール、またはWebページで)印刷するたびに、文字列に変換する必要がありますが、これは暗黙的に発生する可能性があります。double は、それ自体が印刷された表現の定義を持たない浮動小数点ビットです。

double から string への変換がドイツ文化圏で行われる場合、"0,1" が表示されます。

これを印刷してみる

d.ToString(CultureInfo.InvariantCulture)
于 2013-05-16T21:22:26.747 に答える