cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
alunhughes
Level: Powered On

Enforce value in input box to be rounded number

Hi,

 

I'm creating an expenses PowerApp and I have a distance travelled form input field. I want to restrict users from bein. able to input values with decimal places and have the figures automatically rounded to the nearest whole number within the textbox.

 

I've been trying to use the Round() function but can't seem to get it to work to automatically change the number within the textbox from say "41.2" to "41" on the "On Change" property.

 

Can this be done or does it require RegEx on text input?

 

Thanks in Advance,

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Enforce value in input box to be rounded number

Hi @alunhughes ,

The OnChange property of the Text Input box would be fired only when you move the mouse focus from the Text Input box to other places in the screen of your app.

If you want the entered value within the Text Input box to be rounded automatically, I afraid that there is no way to achieve your needs in PowerApps currently.

 

As an alternative solution, I think the Timer control could achieve your needs. I have made a test on my side, please take a try with the following workaround:15.JPG

 

16.JPG

Add a Timer control in your app, set the Duration property to following:

1000

set the AutoStart property and Repeat property to following:

true

set the OnTimerEnd property to following:

If(
"." in TextInput1.Text,
Set(RoundedValue, Round(Value(TextInput1.Text), 0));Reset(TextInput1)
)

Set the Visible property to following:

false

Set the Default property to follwing:

RoundedValue

Please check the following GIF screenshot for more details:Test.gif

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Community Support Team
Community Support Team

Re: Enforce value in input box to be rounded number

Hi @alunhughes ,

The OnChange property of the Text Input box would be fired only when you move the mouse focus from the Text Input box to other places in the screen of your app.

If you want the entered value within the Text Input box to be rounded automatically, I afraid that there is no way to achieve your needs in PowerApps currently.

 

As an alternative solution, I think the Timer control could achieve your needs. I have made a test on my side, please take a try with the following workaround:15.JPG

 

16.JPG

Add a Timer control in your app, set the Duration property to following:

1000

set the AutoStart property and Repeat property to following:

true

set the OnTimerEnd property to following:

If(
"." in TextInput1.Text,
Set(RoundedValue, Round(Value(TextInput1.Text), 0));Reset(TextInput1)
)

Set the Visible property to following:

false

Set the Default property to follwing:

RoundedValue

Please check the following GIF screenshot for more details:Test.gif

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

alunhughes
Level: Powered On

Re: Enforce value in input box to be rounded number

Hi,

 

Thanks so much for this. I didn't need the timer element as updating on the "OnChange" when moving focus aay from the control was sufficient (but this added piece of information improves it also). The issue turned out to be that I was trying to update the values directly within the textbox control rather than using a variable.

 

Works a treat!

 

Thanks!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,003)