C
C#•12mo ago
Loan

ASP.NET Web API doesn't parse floating numbers with a '.'

Hi everyone, I have a quick question about ASP.NET I am scratching my head over this for an hour now. Why when I ask a simple float number in my controller and I give for exemple ''12.547" it does not get parsed and just returns to the calling client this response:
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-975a6f23fd686e43f96af5532f544f5b-83eec17e49f1b737-00",
"errors": {
"Time": [
"The value '1572.752214' is not valid for Time."
]
}
}
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-975a6f23fd686e43f96af5532f544f5b-83eec17e49f1b737-00",
"errors": {
"Time": [
"The value '1572.752214' is not valid for Time."
]
}
}
It might be a culture problem, because my computer is in french, and floating numbers are formatted like '12,547' for example. But I did not find any way of telling ASP to use the en-US culture. Any idea? Thank you so much.
3 Replies
Kiel
Kiel•12mo ago
I am not an asp.net expert, but you could try adding this shortly before your web host runs (in Program.cs perhaps?)
var cultureInfo = new CultureInfo("en-US");

CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
var cultureInfo = new CultureInfo("en-US");

CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
Kiel
Kiel•12mo ago
Stack Overflow
Set CultureInfo in Asp.net Core to have a . as CurrencyDecimalSepar...
I'm going mad. I just want the culture used in the entire Asp.net core application to be set to "en-US". But nothing seems to work. Where to I set the culture for the entire application? I'm not
Loan
LoanOP•12mo ago
I am going to end my life 😭 You are right, I tried by setting the CultureInfo.CurrentCulture & CultureInfo.CurrentUICulture (which is not working) But I haven't though about the THREAD Culture... because ASP is multi threaded Anyway, works like a charm now, thank you so much, I'll stop wasting time on this 😅
Want results from more Discord servers?
Add your server