2nd take - how to round an input value?

I’m back with this question: how to round an input to nearest 1000? For example, if a user enters 1234 it should round to 1000 and display 1000 instead of 1234.

The previously suggested solution was to use a custom state = ((Input X /1000) rounded to 0) * 1000. That produces a round number for the input. However, it was subsequently discovered that when loading the page, setting the custom state to the initial value introduces too much delay, it occasionally takes longer to set the initial condition of the state than it does to load the graph element that uses the Input. The Input feeds a repeating group for the graph. Consequently the repeating group comes up with all zeros where data should be from the custom state. It happens only occasionally but enough to make it unusable.

Since the “initial content” of the Input is the custom state, it can’t be set to a fixed initial value and function as a custom state at the same time. …

Any other ideas?

:slight_smile:

Hi 1theritzy

I’ll try to help here…

  1. You can round in the data source and not use the custom state. Instead of storing the rounded value in a custom state, you can directly reference ((Input’s value / 1000) rounded to 0) * 1000 in the RG’s data source or in the text elements/fields inside the RG. This way, you’re calculating on-the-fly when the RG loads rather than waiting on a custom state.

  2. Stick with using a custom state and use a workflow “when input value is changed”. Leave the initial content as whatever original value you need, do When Input A’s value is changed → Set State (that state is the rounded value). In the RG reference the rounded custom state. This ensures the customs tate only updates after the user eneters (or the page loads the default into) the Input, reducing the chance of a race condition on page load.

  3. You could temporarily hide the RG / put a slight delay after page load to avoid the race condition. Maybe like… load the RG data after a short pause or via a “Do when condition is true” workflow (condition: CustomState is not empty). This isn’t elegant, but it can prevent that timing issue.

Let me know what happens :slight_smile:

Hi Cody. My name Dana, too. :slight_smile:

Thanks for the ideas. None of them seem to fit my parameters.

What I really want is to have a fixed initial content in the input element and then use a condition to change the initial content to custom state when the input is changed. But there is no option for ‘when “this input’s value is changed”’ in the element condition and I don’t think it can be done in the workflow action either (despite what bubblebot tells me).

image