pcui icon indicating copy to clipboard operation
pcui copied to clipboard

Percentages in math ops for number fields

Open LeXXik opened this issue 5 years ago • 5 comments

The current feature of doing math operations, like adding number values in the number fields is super helpful. If possible, please enable adding percentages as well. For example, current value is 123. Allow the use of 123+10%, which would add 10 percent of the current value to the current value.

LeXXik avatar Nov 25 '20 17:11 LeXXik

Hey @ellthompson - should I transfer this issue to the PCUI repo, or do you think this request should remain Editor-specific?

willeastcott avatar Nov 03 '22 00:11 willeastcott

This should be moved to PCUI as it's a feature request for the NumericInput component. We'll need to update the logic here: https://github.com/playcanvas/pcui/blob/ad64183f99aeb75bf99316c30774f21403027891/src/components/NumericInput/index.ts#L199

ellthompson avatar Nov 03 '22 14:11 ellthompson

So my attempt to implement this was rejected and reverted. Can we be clear about the exact functionality of what's desired here, please?

Is it purely:

  • NumericInput has 200 set.
  • User edits the field to 200 + 10%
  • User presses Enter
  • NumerInput evaluates to 220

Questions:

  • Supported operators would be +, - but should * and /` be allowed?
  • Should expressions work with this?

@Maksims, @LeXXik - please comment.

willeastcott avatar Jan 03 '25 15:01 willeastcott

The addition/subtraction looks correct, yes. Basically: a + c% = a + (a * c) Where c is floating representation of a percentage (10% = 0.1; 150% = 1.5; etc). With multiplication/division, it is even more direct: 200 * 10% = 20, so a * c% = a * c.

Maksims avatar Jan 03 '25 18:01 Maksims

Good, good. I think personally, I would go with a bare minimum in this PR. That is I'd just add plus and minus operands, as you described them. Its actually, the operation I wanted originally in this issue. I don't really see a value in mul/div, but perhaps someone is used to use those in some other apps. I'd leave those until a feature request is made, though.

LeXXik avatar Jan 03 '25 20:01 LeXXik