Another take on this.
- Create a Number Input Component:
- Add a Number Input component to your Retool app.
- Name it
numberInput
.
- Create a Text Component for Displaying Rounded Value:
- Add a Text component to display the rounded number.
- Name it
roundedDisplay
.
- Write a JavaScript Query to Handle the Rounding:
- Create a JavaScript query that rounds the value for display purposes.
- Name the query
roundValue
.
// Get the exact value from the number input
const exactValue = numberInput.value;
// Round the value to two decimal places
const roundedValue = Math.round(exactValue * 100) / 100;
// Set the rounded value to the display component
roundedDisplay.setValue(roundedValue);
// Return the exact value for further use
return exactValue;
- Trigger the JavaScript Query on Number Input Change:
- Go to the
numberInput
component settings. - In the event handler, run
roundValue
query.
- Store the Exact Value for Backend Operations:
- When you need to use the exact value (e.g., for saving to the database), reference the output of the
roundValue
query. - Example:
const exactValue = roundValue.data;
// Use exactValue in your backend operations or save to the database