4 ms·
I suppose that depends on how you implement `times` for the `Percent`-class. One way would be to say that 10% * 2 = 20%, making this expression evaluate to 12,
by occz 2y ago
I suppose that depends on how you implement `times` for the `Percent`-class. One way would be to say that 10% * 2 = 20%, making this expression evaluate to 12, in accordance with Kotlin operator precedence [1].
It's possible to avoid making this decision altogether by not implementing `times` for `Percent`, making the user have to be more explicit about what they actually want to happen - for example, requiring them to add parenthesis to arrive at 22:
val total = (price + 10.percent) * 2
Or to arrive at 11:
val total = price + (10 * 2).percent
[1] https://kotlinlang.org/docs/reference/grammar.html#expressions https://kotlinlang.org/docs/reference/grammar.html#expressio...