Skip to content

Dashboard chapter 12 amountInCents = amount * 100 doesn't convert to integer. #636

Open
@tpdickson

Description

@tpdickson

In Chapter 12:

https://nextjs.org/learn/dashboard-app/mutating-data#storing-values-in-cents

The dollar amount is converted to cents by multiplying by 100. However, this doesn't convert it to an integer and can lead to database errors. The value after multiplication needs to be rounded (Math.round(amount * 100)).

For example, entering 2.55:

image

Database Error: Failed to Update Invoice. NeonDbError: invalid input syntax for type integer: "254.99999999999997"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions