node.js: string decimals in best practices#2640
Open
johannes-vogel wants to merge 2 commits into
Open
Conversation
renejeglinsky
left a comment
Contributor
There was a problem hiding this comment.
Clearer Do and Don't
|
|
||
| #### Do arithmetic in the database { .good } | ||
|
|
||
| Avoid calculations on `Decimal` / `Int64` fields in JavaScript — do them in the database instead: |
Contributor
There was a problem hiding this comment.
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 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. | ||
| ::: |
Contributor
There was a problem hiding this comment.
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. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.