Help needed in string format
# help-with-umbraco
r
I added a textString property to store map co-ordinates to a document type "Contact". In my contactService, I am getting some encoded value for the negative sign while getting the latitude contact.Latitude. var contact = umbracoContextReference.UmbracoContext.Content?.GetById(Convert.ToInt32(id)) as Contact; Convert.ToDecimal({contact.Latitude}, CultureInfo.InvariantCulture) is working fine for positive decimals. It throws exception on negative decimals for ex. "−25.38273460". I tried applying NumberStyles decimal.Parse(contact.Longitude, System.Globalization.NumberStyles.AllowParentheses | System.Globalization.NumberStyles.AllowLeadingWhite | System.Globalization.NumberStyles.AllowTrailingWhite | System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture); also simple string Replace("−", "-"), Regex.UnEscape(). It didnt work either. Kindly suggest a solution
a
Could it be your using the wrong character for the - symbol?
- vs −
? (you used the latter one in your example) Perhaps something like
string latitudeString = contact.Latitude.Replace("−", "-");
r
You are awesome. The co-ordinates are autogenerated on SAVE and Publish the content. The solution is multi language. When user language is english, it is stored as "-21.98479830" and when user language is Norwegian, it is stored as "−21.98479830" with a different minus sign. I see the difference in the sign after you pointed out. node.SetValue("latitude",coordinates.Latitude.ToString("00.00000000").Replace(",","."));. I need to find a solution to save correct "-" negative sign irrespective of the backoffice user language. Thanks a lot.
@Ambert I am finding it difficult to write the Replace with two types of minus sign. My keyboard has same sign for both hyphen and minus. Is there any way to replace using htmlstring or Unicode values=
a
Perhaps it's easiest to store the decinal as a culture invariant?
If that's possible
Iirc you can add a culture in the tostring method
r
Thanks again. I set culture to Tostring method, it worked
a
Nice work @Ramya Devendiran !
13 Views