tc39 / tc39/proposal-decimal

Normalization in other implementations

Open
#89 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
638
Forks
20
PR merge metrics
No merged PRs in 30d

Description

This week's slides discuss precedent for decimals from other programming languages. I did some quick research on the listed programming languages to see if they support trailing zeros.

Java: YES

https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html

The rounding mode determines how any discarded trailing digits affect the returned result.

stripTrailingZeros()
Returns a BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation.

C#: YES

https://learn.microsoft.com/en-us/dotnet/api/system.decimal?view=net-8.0

The scaling factor also preserves any trailing zeros in a Decimal number. Trailing zeros do not affect the value of a Decimal number in arithmetic or comparison operations. However, trailing zeros might be revealed by the ToString method if an appropriate format string is applied.

Python: YES

https://docs.python.org/3/library/decimal.html

The decimal module incorporates a notion of significant places so that 1.30 + 1.20 is 2.50. The trailing zero is kept to indicate significance. This is the customary presentation for monetary applications. For multiplication, the “schoolbook” approach uses all the figures in the multiplicands. For instance, 1.3 * 1.2 gives 1.56 while 1.30 * 1.20 gives 1.5600.

Ruby: Wasn't able to determine for sure in the short amount of time I took to research, but I think it does not support them. Ruby defines decimals as: "arbitrary-precision floating point decimal arithmetic". When I play with them in irb I can't seem to get a trailing zero to roundtrip.

Postgresql: YES

https://www.postgresql.org/docs/8.1/datatype.html
https://stackoverflow.com/questions/26920157/postgresql-adds-trailing-zeros-to-numeric

An example of the data I am inserting is 0.75 in the numeric(9,3) column and the value stored is 0.750. Another example for the numeric(9,4) column: I insert the value 12 and the DB is holding 12.0000.

@jessealama

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Java, C#, Python, Ruby, and PostgreSQL references linked in the issue, then read the surrounding discussion for the decimal proposal's intended behavior. Done would require a documented decision about trailing-zero normalization and agreement on how that behavior should be specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java, javascript, postgresql, python, ruby
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.