vscode_rainbow_csv icon indicating copy to clipboard operation
vscode_rainbow_csv copied to clipboard

fix: Detect negative numbers

Open krlmlr opened this issue 1 year ago • 4 comments

This allows an optional leading - .

Should we allow a leading + ? What about scientific notation?

krlmlr avatar Jan 03 '25 10:01 krlmlr

@mechatroner: I tweaked the regex to account for the new TODO too.

krlmlr avatar Jan 21 '25 09:01 krlmlr

Should numbers like .3 or -.5 be supported too?

krlmlr avatar Jan 21 '25 09:01 krlmlr

I appreciate you taking the time to fix this. The problem with the negative numbers IMO is that if the column is mixed-signed aligning them as numbers doesn't provide a lot of benefits since it doesn't allow for visual sorting that easily - one also has to take a look at the sign, so it is not much more convenient than just doing a standard length-based alignment. Also if we are handling negative signs the next step is to handle percent sign or dollar sign at the end so this will quickly get more complicated. Basically what I am saying is that current positive-only alignment already covers maybe 75% of use cases for numbers alignment and getting the remaining 25% is a matter of diminishing returns. I might revisit your proposal later, I will keep your pull request open for now.

mechatroner avatar Jan 23 '25 02:01 mechatroner

Thanks, I appreciate the explanation and the rationale. Not pushing for a change here, I can run from my fork 🙃

It is fairly common to have numeric data in CSV files, much less so percentages or values with a currency. It seems worth considering the case of negative numbers separately.

We could do pretty cool stuff with inlays here too:

  • left-align the leading minus, right-align the number
  • add thousand separators (zero-width or not) as inlays -- 12'345'678

krlmlr avatar Jan 23 '25 07:01 krlmlr