If you could add something to Kentico, what would it be and why?

Use Decimal instead of Double for all financial calculations

Kentico ecommerce unfortunately suffers from rounding errors at times. The reason for this is because the Double type has been used rather than Decimal.

All financial calculations (e.g. calculating the total basket cost) should be done using the Decimal type - it's what it was created for because Double's simply don't offer enough precision.

See these links:
http://msdn.microsoft.com/en-us/library/364x0z75.aspx
http://stackoverflow.com/questions/1165761/decimal-vs-double-which-one-should-i-use-and-when

Please stop using Double, and starting use Decimal instead.

73 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Ian shared this idea  ·   ·  Admin →

    5 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Sean Wright commented  · 

        Our 3rd party integration libraries for payment all use the decimal type, so we use decimal in our internal libraries and expose APIs to do the conversion from Kentico wherever our libraries touch Kentico because we know we will be given a double to deal with.

        Seeing as how using a decimal for monetary calculations is a standard for c# community this would be a nice change and would not require a huge refactor (for our team at least).

      • Ian commented  · 

        Hi Petr, I'm open for looking at this and I'm sure I can get some other developers over here to take a look.

      • Ian commented  · 

        Hi Petr - Unfortunately I think it would have to be a breaking change in the API. However I think it would be a worthwhile one, I'd have the confidence that all future projects are going to apply conversions correctly and charge a customer the right price.

        Alternatively you could add a different property, on a ShoppingCart change TotalPrice to Price and mark the old one as deprecated

      • Ian commented  · 

        Honestly I'd say it was quite a big mistake not using Decimals in the first place. I think in this instance I would suggest making a breaking change (this would result in Double/Decimal) compile errors which are quite straight forward to fix to provide the benefit of a calculation system that actually works. I'd certainly take the hit spending an hour casting things back to Double if need be to have confidence and correctness in the underlying engine.

        I honestly imagine people would be taking code out that works around these rounding errors so it would benefit most people.

      Feedback and Knowledge Base