Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistent formation number with numeric separator #8594

Open
alexander-akait opened this issue Jun 18, 2020 · 6 comments
Open

inconsistent formation number with numeric separator #8594

alexander-akait opened this issue Jun 18, 2020 · 6 comments
Labels
lang:javascript Issues affecting JS status:needs discussion Issues needing discussion and a decision to be made before action can be taken

Comments

@alexander-akait
Copy link
Member

Prettier 2.0.5
Playground link

--parser babel

Input:

const number = 1_000_000.000;
const number = 1_000_000.0_0_0;

Output:

const number = 1_000_000.0;
const number = 1_000_000.0_0_0;

Expected behavior:

const number = 1_000_000.0;
const number = 1_000_000.0;

Will be great to hear other opinions.

@alexander-akait alexander-akait added the status:needs discussion Issues needing discussion and a decision to be made before action can be taken label Jun 18, 2020
@Skalman
Copy link

Skalman commented Jun 19, 2020

I think I'd prefer Prettier not to modify numbers with numeric separators at all. Using a numeric separator at all is a type of manual formatting, and I don't see how Prettier can determine what was meant originally.

I'd prefer the following not to be reformatted at all:

const number = 1_000_000.000;
const number = 1_000_000.0_0_0;
const number = 1_000_000.0_0_1;
const number = 1_000_000.0_0_2;

@fisker
Copy link
Sponsor Member

fisker commented Jun 19, 2020

But we format

const number = 1000000.0;
const number = 1000000.000;
const number = 1000000.001;
const number = 1000000.002;

@thorn0
Copy link
Member

thorn0 commented Jun 19, 2020

@fisker The difference is that there is no separators in your examples.

@thorn0 thorn0 added the lang:javascript Issues affecting JS label Jun 23, 2020
@sgregson
Copy link

I feel the same as @Skalman, I'd prefer prettier not format numeric separators. By way of example, the https://github.com/tc39/proposal-numeric-separator proposal's motivation demonstrate some common use cases for variable in placement of numeric separators, particularly around storing currency information without floating point numbers:

1_000_000_000           // Ah, so a billion
101_475_938.38          // And this is hundreds of millions

let fee = 123_00;       // $123 (12300 cents, apparently)
let fee = 12_300;       // $12,300 (woah, that fee!)
let amount = 12345_00;  // 12,345 (1234500 cents, apparently)
let amount = 123_4500;  // 123.45 (4-fixed financial)
let amount = 1_234_500; // 1,234,500

The ability to place the separator intentionally at either the 3rd (currency), 4th (standard thousands), or 5th character (4-fixed financial) left of the decimal feels important to preserve.

@yoyo837
Copy link

yoyo837 commented Aug 12, 2021

Waiting for this feature.

@ELI7VH
Copy link

ELI7VH commented Nov 9, 2023

this should be a feauture. Myself, and many projects that I am on also would find it useful.

I don't see the big deal here, because a few people say "i don't want prettier to do this", then just simply don't enable it - why is this an argument.

The fact is there are certain projects and teams that would like this feature, and it is indeed a formatting issue - which, unless I am mistaken is the job of something like Prettier, is it not?

Everybody is throwing edge cases around, but why not just add an easy way to format it..

{
  "numeric_formatting": "(x)_###.###"
}

this would put an underscore after every 3rd digit, and retain a zero padding of N digits.

the syntax seems fairly simple and straightforward, and could probably cover most use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang:javascript Issues affecting JS status:needs discussion Issues needing discussion and a decision to be made before action can be taken
Projects
None yet
Development

No branches or pull requests

7 participants