cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Highlighted
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
Highlighted
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
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (3,693)