DEV Community

Cover image for Power Apps form – Setting Currency Format at Runtime
Surjyo Bhattacharya
Surjyo Bhattacharya

Posted on

Power Apps form – Setting Currency Format at Runtime

Recently came across a requirement where the user expected the currency formatting at runtime.
Power Apps does not inherently support any currency input for a text box.
We currently have the input formats as Number and Text as represented below:

Image description

We need to keep the input text field format as Number to prevent the user from inserting non-numeric values in the said field.
Now the question arises as how we can display formatting at runtime.

Option 1 :
From the text box input , the event that we can capture is the OnChange , so while tabbing out the formatting is enabled and user can see the formatted value in the text box itself.
For this we need to set a variable with the formatted value on the OnChange Event as shown:

Image description

Code :

Set(
FormattedCurrency,
Text(
Value(txtUnitPrice.Text),
"$#,##0.00",
Language()
)
)

We need to do one additional step, i.e set this Variable - FormattedCurrency defined above as the Default attribute of the TextBox input.

Image description

This enables near runtime formatting, with the formatting enabled on the tab event.

Options 2 :
If the user is expecting formatting while typing itself and not willing to wait for the tabbed event,
we can add a label adjacent the text box and set its Text property as below :

Image description

Code :

Text(
Value(txtUnitPrice.Text),
"$#,##0.00",
Language()
)

With these settings we can generate our desired output :

Step 1 : While typing the numbers in the Currency text box field :

Image description

Step 2 : OnTabbing out

Image description

You can replace the textbox controls with the data card controls in case you are working in an integrated SharePoint PowerApps solution.

Top comments (0)