Skip to content

node.js: string decimals in best practices#2640

Open
johannes-vogel wants to merge 2 commits into
mainfrom
string-decimals
Open

node.js: string decimals in best practices#2640
johannes-vogel wants to merge 2 commits into
mainfrom
string-decimals

Conversation

@johannes-vogel

@johannes-vogel johannes-vogel commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

adds a section in the node.js best practices for now.
eventually this might move to the databases section but that's rather empty atm for node and the top level guide also does not yet fit imo.

@renejeglinsky renejeglinsky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearer Do and Don't

Comment thread node.js/best-practices.md

#### Do arithmetic in the database { .good }

Avoid calculations on `Decimal` / `Int64` fields in JavaScript — do them in the database instead:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Avoid calculations on `Decimal` / `Int64` fields in JavaScript — do them in the database instead:
Calculations on `Decimal` / `Int64` fields should be done in the database:

Comment thread node.js/best-practices.md
Comment on lines +397 to +399
::: warning Integer arithmetic can exceed JavaScript's safe range
Multiplication or addition on integer fields can produce values beyond `Number.MAX_SAFE_INTEGER`. Doing such calculations in JavaScript risks silently losing precision — do them in the database instead.
:::

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
::: warning Integer arithmetic can exceed JavaScript's safe range
Multiplication or addition on integer fields can produce values beyond `Number.MAX_SAFE_INTEGER`. Doing such calculations in JavaScript risks silently losing precision — do them in the database instead.
:::
#### Arithmetic in Javascript {.bad}
Calculations on `Decimal` / `Int64` fields in JavaScript should be avoided as integer arithmetic can exceed JavaScript's safe range. Multiplication or addition on integer fields can produce values beyond `Number.MAX_SAFE_INTEGER`. Doing such calculations in JavaScript risks silently losing precision — do them in the database instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants