Number formatting "comma" doesn't seem to work

I’m trying to use the hint regarding numerical formatting that is provided here, understanding this as python-style format string.

However, I’m unable to cause the formatting to use comma (,) as the thousands separator (underscore works…)
Here’s a simple example:

custom_data:
  test:
    plot_type: "table"
    headers:
      value:
        format: "{:,.2f}"
sp:
  test:
    fn: "hello.txt"

and hello.txt contains:

sample value
test 100000.55555

The resulting html has the following:

image

i.e. the .2f was understood, but the , was ignored.

changing the comma to an underscore results in

image

I’m sure I’m doing something wrong…but I can’t figure out what it is…

Thanks for your help!

MultiQC does a bit of non-standard handling of decimal places and thousand separators, see the docs:

It starts off with a format string, but then uses config.thousandsSep_format.

This works as expected:

thousandsSep_format: ','
custom_data:
  test:
    plot_type: "table"
sp:
  test:
    fn: "hello.txt"

The reason for this in the code goes back a long way. I think that there are two reasons: consistent functionality across tables and plots, and also being able to have space separators with a “fake” space. What I mean is that if you copy a number from a MultiQC table with a space separator, it’s copied without a space. This is because it’s actually a HTML <span> element.

It could be nice to revisit this code in the future and see if we can refactor it to work in a better way.

thanks for the quick reply.

The “fake space” is a nice touch, too bad one cannot have “fake commas” as well, i.e. commas that do not get copied when copying the text.

A note for future reader (probably me…), if you do change the format string, you can only use f, and if you want the thousandsSep_format to be honored, you still need to include the comma in your format string.

1 Like