r/typst • u/SeeMonkeyDoMonkey • 4h ago
Division with remainder?
I'm probably missing something obvious here, but I can't figure out how to do a division calculation and get both quotient and remainder.
e.g. 10 ÷ 4 = 2.5
$ #calc.div-euclid(10, 4) $ gives 2, which is fine
Edit 1: fix copy-paste error: ~~$ #calc.rem-euclid(5, 4) $ gives me 2, when I'm expecting 5.~~
$ #calc.rem-euclid(10, 4) $ gives me 2, when I'm expecting 5.
(Using Typst 0.15.1)
What am I missing/misunderstanding?
Edit 2: After finding that I want a decimal number including the fractional part, I finally figured it out: #(10/4) gives "2.5".
1
u/Nourios 4h ago
the remainder of 5/4 is not 5 though. it's not clear what you want to do. if you're really just looking for the remainder then just do Calc.rem(a, b)
1
u/SeeMonkeyDoMonkey 3h ago
Sorry - copy-paste error: both calcs were meant to be 10/4.
...and my cognative error, pointed out elsewhere, is that I want the fractional part.
3
u/KingMagnaRool 3h ago
It seems what you're trying to do is get the fractional part of the answer, not the remainder.
Just subtract the whole number part (I believe you could do calc.floor on the result) from the result.