Skip to content

Thousands separators #5142

Answered by Erenedim
Erenedim asked this question in Q&A
Oct 6, 2024 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

Just want to add I found an error in your code.

If you format the number 3.08233 or 3.008233 it will be displayed as 3.82 (removing the zero in the decimal).

I have made an updated format function redoing the decimals part of the function and renaming decimals to digits to make it interchangeable with the build-in round function:

#let fmt_number(
  number,
  digits: 3,
  decimal_sep: ".",
  thousands_sep: ","
) = {
  let integer = calc.trunc(number)
  let decimal = calc.fract(number)
  let res = str(integer).clusters()
                        .rev()
                        .chunks(3)
                        .map(c => c.join(""))
                        .join(thousands_sep)
               …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Erenedim
Comment options

@Erenedim
Comment options

Answer selected by Erenedim
Comment options

You must be logged in to vote
1 reply
@Erenedim
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants