Hey Fabian,
I had a similar issue to this when using a text field.
It's exactly as you said, using the Swedish culture (eg decimal comma "1,0" is "1.0").
I've found the best way when dealing with multiple cultures is to have an agreed backoffice format (typically culture invariant which uses decimal points) and then convert that value into the current culture for display purposes.
Of course, you're free to use whatever culture you want for dashboard values and then once you have the parsed decimal using ToString to display it with the given culture.
Yes in the backoffice everything is being inputted in one format which is culture invariant which uses decimal points, so that is not an issue.
The issue is that almost always in order to get a property value in umbraco i n order to display it we use the following code:
value = meal.GetPropertyValue<decimal>(alias);
But now due to the explained issue in my first comment I can't use it. How are you doing in order to get the property value in order to avoid the mentioned issue? Can you post a code example please?
Hey Fabian,
Understood. I meant to post some code before but got sidetracked.
What I've done in the past is the following:
var value = meal.GetPropertyValue<string>(alias); // value of say 15.00
var decimal = Decimal.Parse(value, NumberStyles.Any, CultureInfo.InvariantCulture); // Now a decimal of 15.00
decimal.ToString("<YourFormat>"); // With a given format (eg. "F" or "C") this will now display as 15,00 rather than 15.00
It's important to note that functions like TryParse, Parse, ToString use the current thread culture which is set to sv-SE, so setting the Decimal.Parse to invariant will allow you to parse an expected format.
The key really is to ensure that what you're parsing from is always consistent. What you're displaying isn't so important as the ToString & current culture will handle that.
Thanks a lot for your response, answer was marked as a solution.
In an ideal world the GetPropertyValue() method would have a parameter in order to tell it to ignore the culture, but till then we make use of this solution.
Get Property Value for decimal in swedish culture returning 0
I have a multilingual site and when you switch to the the swedish culture (sv-SE) everywhere where I am using the code below returns 0.
I think its because that the swedish culture doesn't use . as the decimal seperator, more info on this here.
Isn't there away to tell the GetPropertyValue method to ignore the culture or something?
As a workaround I had to implement the following code for now but its not that pretty.
Does anybody has any solution to this issue?
Thanks for the help
Hey Fabian,
I had a similar issue to this when using a text field.
It's exactly as you said, using the Swedish culture (eg decimal comma "1,0" is "1.0").
I've found the best way when dealing with multiple cultures is to have an agreed backoffice format (typically culture invariant which uses decimal points) and then convert that value into the current culture for display purposes.
Of course, you're free to use whatever culture you want for dashboard values and then once you have the parsed decimal using ToString to display it with the given culture.
Thanks,
Jamie
Hey Jamie,
Yes in the backoffice everything is being inputted in one format which is culture invariant which uses decimal points, so that is not an issue.
The issue is that almost always in order to get a property value in umbraco i n order to display it we use the following code:
But now due to the explained issue in my first comment I can't use it. How are you doing in order to get the property value in order to avoid the mentioned issue? Can you post a code example please?
Thank you very much for your help.
Hey Fabian, Understood. I meant to post some code before but got sidetracked.
What I've done in the past is the following:
It's important to note that functions like TryParse, Parse, ToString use the current thread culture which is set to sv-SE, so setting the Decimal.Parse to invariant will allow you to parse an expected format.
The key really is to ensure that what you're parsing from is always consistent. What you're displaying isn't so important as the ToString & current culture will handle that.
I hope this helps.
Thanks,
Jamie
Hi Jamie,
Thanks a lot for taking your time in order to help me out, really appreciate it.
One last question if I may, in the umbraco backoffice are you storing the decimal values in a textstring data type or in a decimal data type?
Thanks
That'd be dependant on the data type but I'm fairly sure a numeric or textstring is stored as text data. So all GetPropertyValue
If my answer above help please mark it as the solution :)
Hi Jamie,
Thanks a lot for your response, answer was marked as a solution.
In an ideal world the GetPropertyValue() method would have a parameter in order to tell it to ignore the culture, but till then we make use of this solution.
Thanks
is working on a reply...