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

strfmt("{:.0}", -0.1) should omit negative sign #4

Closed
ntjess opened this issue Dec 8, 2023 · 3 comments
Closed

strfmt("{:.0}", -0.1) should omit negative sign #4

ntjess opened this issue Dec 8, 2023 · 3 comments

Comments

@ntjess
Copy link

ntjess commented Dec 8, 2023

#strfmt("{:.0}", -0.1) displays as -0, where 0 would be more appropriate

@PgBiel
Copy link
Owner

PgBiel commented Dec 8, 2023

This is expected behavior, as it's how Rust does it, and this package aims to be as close as possible to Rust's format! function. You could use something such as

#let old-strfmt = strfmt
#let strfmt(..args) = {
  let result = old-strfmt(..args)
  if result == "-0" { "0" } else { result }
}

We could consider adding some sort of custom flag which just does that, but I'm not sure if it's worth it...
So I'll be closing the issue for now, but thanks for bringing this up.

@PgBiel PgBiel closed this as completed Dec 8, 2023
@ntjess
Copy link
Author

ntjess commented Dec 8, 2023

Thanks for the explanation, I should've checked before submitting the issue. Typst itself also formats in this way.

However, note that "-" is different from MINUS (0x2212) so you may want to change the char code such that it aligns with non-special cases:
image

@PgBiel PgBiel reopened this May 5, 2024
@PgBiel
Copy link
Owner

PgBiel commented May 5, 2024

Thanks @ntjess, I hadn't noticed the character was different until now! For now, I've elected a normal hyphen to be displayed in all cases instead. Perhaps we can change this in the future if needed.

@PgBiel PgBiel closed this as completed May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants