I'm trying to unit test a getprice method using NUnit. I am stuck with parsing the rawprice into double. My cultureinfo is en-US
but I set it to de-DE
for this test. Double parsing with numberstyles.any and invariantculture returns unexpected result.
The rawprice cultureinfo is unknown, it can be any. Also the server where it will run is also unknown and can be in any language.
For this test, I tried German for the rawprice and machine.
I tried parsing "9,42"
but the result is 942
.
[Test]
[SetCulture("de-DE")]
public void GetPrice_PriceTextWithCommaDecimal_ReturnsInvariantPrice()
{
var rawPriceText = "9,42";
double.TryParse(rawPriceText, NumberStyles.Any, CultureInfo.InvariantCulture, out double price);
//parsed price result is 942
...
}