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
Comments
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; |
But we format const number = 1000000.0;
const number = 1000000.000;
const number = 1000000.001;
const number = 1000000.002; |
@fisker The difference is that there is no separators in your examples. |
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. |
Waiting for this feature. |
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..
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. |
Prettier 2.0.5
Playground link
Input:
Output:
Expected behavior:
Will be great to hear other opinions.
The text was updated successfully, but these errors were encountered: