PgBiel / typst-oxifmt

Convenient Rust-like string formatting in Typst (previously "typst-strfmt")
Apache License 2.0
32 stars 0 forks source link

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

Closed ntjess closed 7 months ago

ntjess commented 12 months ago

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

PgBiel commented 12 months ago

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.

ntjess commented 12 months ago

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 commented 7 months ago

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.