C
C#5mo ago
PIE

✅ Strange parsing error with docker instance

So I have a program that scrapes prices and parses them into longs with these lines of code
HttpResponseMessage page = await client.GetAsync({the link});
HttpResponseMessage page = await client.GetAsync({the link});
long itemCost = long.Parse(itemCostElement.TextContent, NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol);
long itemCost = long.Parse(itemCostElement.TextContent, NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol);
however I got this error
The input string '$79,156' was not in a correct format.
The input string '$79,156' was not in a correct format.
Is this because of unicode differences in linux that doesn't work well with docker images made in windows? The above code seems to work fine on my windows machine.
6 Replies
Angius
Angius5mo ago
Probably a matter of system culture In some cultures, , is a decimal separator, in some it's a thousands separator, etc Could be that your dev culture is different from the prod culture
PIE
PIEOP5mo ago
hm would something like
long itemCost = long.Parse(itemCostElement.TextContent, NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol, CultureInfo.InvariantCulture);
long itemCost = long.Parse(itemCostElement.TextContent, NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol, CultureInfo.InvariantCulture);
work then? ah yes tested with invariant Culture and returns the same error
Angius
Angius5mo ago
Probably because invariant culture's currency symbol is ¤
MODiX
MODiX5mo ago
Angius
REPL Result: Success
using System.Globalization;
var f = new CultureInfo("en-US").NumberFormat;
new {
Sep = f.CurrencyGroupSeparator,
Cur = f.CurrencySymbol
}
using System.Globalization;
var f = new CultureInfo("en-US").NumberFormat;
new {
Sep = f.CurrencyGroupSeparator,
Cur = f.CurrencySymbol
}
Result: <>f__AnonymousType0#1<string, string>
{
"sep": ",",
"cur": "$"
}
{
"sep": ",",
"cur": "$"
}
Compile: 328.036ms | Execution: 61.385ms | React with ❌ to remove this embed.
Angius
Angius5mo ago
You're probably looking for the en-US culture
PIE
PIEOP5mo ago
ok thanks o/ worked
Want results from more Discord servers?
Add your server