question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Decimal type (Arbitrary Precision Numbers)

See original GitHub issue

Problem

The representation of Decimals and Floats are fundamentally different. Postgres supports the concept of Arbitrary Precision Numbers via the numeric/decimal type.

It would be useful for Prisma to provide a core data type Decimal to live alongside Float and Int in order to support arbitrary precision numbers.

Suggested solution

Since the javascript Number type does not support arbitrary precision numbers fields with this value could be types as javascript String types.

Alternatives

Arbitrary precision values can be stored in a String field, however this prevents filtering/sorting/aggregation. Values could also be stored as a Float, but this loses the arbitrary precision which is important in many applications. Values could also be stored as Int, with the decimal shift accounted for manually, but this does not support arbitrary levels of precision in the was a postgres decimal value does.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
pantharshit00commented, Jan 22, 2021

Decimal support was released in the preview of native types: https://www.prisma.io/docs/concepts/components/preview-features/native-types/native-types-mappings#decimal

I think we never posted an update here so here we go.

Client maps any Decimal value to decimal.js object.

1reaction
timsuchanekcommented, Feb 3, 2021

As this is implemented, I’ll close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Arbitrary-precision Decimal Floating-Point Numbers
In this design, closer in spirit to usual floating-point binary numbers, we represent decimal numbers are pairs of arbitrary-precison integers, ...
Read more >
Arbitrary-precision arithmetic - Wikipedia
Arbitrary precision is used in applications where the speed of arithmetic is not a limiting factor, or where precise results with very large...
Read more >
Support for Decimal type (Arbitrary Precision Numbers) #3374
Problem The representation of Decimals and Floats are fundamentally different. Postgres supports the concept of Arbitrary Precision Numbers ...
Read more >
decimal — Decimal fixed point and floating point arithmetic ...
The decimal module provides support for fast correctly rounded decimal floating point arithmetic. It offers several advantages over the float datatype:.
Read more >
Store arbitrary precision numeric data | Cloud Spanner
NUMERIC in the PostgreSQL dialect is an arbitrary decimal precision numeric type (scale or precision can be any number within the supported range)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found