Author: andre_kendeck

  • When working with money, use cents

    When working with money, use cents

    A common problem developers run into when working with currency is floating-point precision errors.

    On small amounts this looks harmless, but at scale it becomes dangerous! Over millions of transactions, these tiny inaccuracies can compound and can lead to reporting errors.


    So why not just use cents?

    Simple. right?


    But what about currencies with huge numbers?


    Let’s take the Indonesian Rupiah as an example.

    currently @ R1,000 = Rp 1,000,000

    Most programming languages can handle the value of a large integer up to 9,223,372,036,854,775,807 (That’s roughly 9 quintillion)

    To actually hit this limit using cents, you’d need transaction data equivalent to about 1 quadrillion rands.

    To reach 1 quadrillion rand, you would need to average:

    R10 trillion per year FOR 100 years.

    That’s more than the entire South African GDP, every year, for a century.

    Performance??? Dude really??

    If your system is processing that much transaction volume, you probably already have serious infrastructure, accounting, and scaling strategies in place. At this scale the price of RAM is not a concern.

  • PHP Enums are underrated!

    Honestly, PHP 8.1 was the best release of PHP since version 7.

    The PHP Core team really nailed enums in PHP.

    Most programming languages have enums, but many are just syntactic sugar around constants.

    Most developers see enums as a place to store constants and move on. However, enums can do much more than that. Since enums can implement interfaces and contain functions, a lot more logic and validation can be achieved.

    JSON Representation

    Have you ever needed to ensure that frontend select fields match your backend select fields?

    As far as I know, JsonSerializable is the only built-in interface that an enum can implement.

    Different Data Types, Same Meaning

    Sometimes your system integrates with another system that has a similar constant, but represents it in a different form.

    Related Constants

    It’s very likely you’ve run into a situation where one constant is related to another—for example, Roles & Permissions or SubscriptionType & ProductFeatures.

    Type Safety (Probably the Most Important)

    A language like PHP needs more type safety. Honestly.