Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tony Lorentzen 85 posts 174 karma points
    Dec 17, 2020 @ 15:02
    Tony Lorentzen
    0

    Converting Decimals and cultures

    Som, I'm importing a bunch of "products" from E-conomic and converting those into pages in Umbraco. The prices I'm receiving from E-conomic are using dot indicators for decimals i.e. "9999.95". The value is being imported into a SQL Server (using datatype: Decimal(10,2) first - then into Umbraco using a timed script also into a Decimal field, but I have problems when switching the page culture from English to Danish in my Razor scripts. It's like it's totally discarding the dot. Printing out the value of the decimal datatype using Culture "en-EN" it says: 9999.95 but switching to "da-DK" is comes out as "999995" which obviously is wrong. Opening that specific page in Umbraco and saving it somehow converts that number to the correct number. Looking directly at the data in the database I see no difference before and after the save. Anyone know what's going on? Thanks!

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Dec 20, 2020 @ 04:52
    Huw Reddick
    0

    What code are you using to display the decimal?

  • Tony Lorentzen 85 posts 174 karma points
    Jan 11, 2021 @ 23:19
    Tony Lorentzen
    0

    @string.Format("{0:#,###,###.##}", productPrice)

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Jan 12, 2021 @ 12:16
    Huw Reddick
    0

    you need to provide a culture to format numbers correctly in different languages.

    Examples https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings?redirectedfrom=MSDN

  • Tony Lorentzen 85 posts 174 karma points
    Jan 12, 2021 @ 12:45
    Tony Lorentzen
    0

    I already set the culture format in the top of my document - that's not the problem. The problem has to do with Umbraco somehow, but I haven't been able to figure out what it is. I get the value from a web-service like "182.82" and convert that to a decimal in .NET. That is tested and the number is correct... So far so good. When I create my Umbraco page in .NET programmatically I insert that value into an Umbraco.Decimal field. Then when rendering the value on the frontend somehow the decimal is gone and the number is converted to "18282". I tested the value if it's larger than 10000 and it is... In other words - it's not a display or culture issue. Yet, in the Umbraco Backoffice when I open to edit that page it's being displayed correctly in the field and if I hit "Save & publish" afterwards it will show up correct on the frontend. Super weird. However - I've been able to fix this by converting the value to a Double in .NET before creating the page and that seems to fix the issue. I checked the database and I see that the field holding property values of type "Umbraco.Decimal" are actually Numeric(38,6) and I think that could be the culprit (maybe).

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Jan 12, 2021 @ 15:00
    Huw Reddick
    0

    sounds like this is the issue then

    When I create my Umbraco page in .NET programmatically I insert that value into an Umbraco.Decimal field. Then when rendering the value on the frontend somehow the decimal is gone and the number is converted to "18282".

    How are you inserting the value into the field? Perhaps you could change your field to a string and parse to decimal after retrieval

Please Sign in or register to post replies

Write your reply to:

Draft