It’s been sometime I wrote a blog on Power Automate. And today’s blog is very simple. And trust me, this requirement is one of the most common requirements.
Convert an input into currency format, for example you want to convert 1234.567 to $1234.567 or for that matter any other currency is one of the most common requirement, especially if we are working on a transactional system.
And to complete this requirement, more often than not, we perform string manipulations. While that works, it’s not the best way to do that, especially when we have the wonderful formatNumber function to take care of it.
The function supports various formatting options but here we are going to talk about the currency formatting only.
Let’s take our previous example. To demonstrate this, I have created an instant flow.
As you can see in the above screenshot, I have declared a string variable – 1234.5678
In the next step, I will use the formatNumber function to convert it into desired currency format. And below is the screenshot of how I do it.
formatNumber(float(variables('TestVariable')), 'C3', 'en-US')
I have used three parameters in the formatNumber function.
- input – If it is text, you need to convert to float or int depending on whether you need the final output with decimals or not
- the currency format – the keyword ‘C‘ is the format to specify that it is currency. I am passing C3 here. The number here denote the number of decimal places I wish to return.
- Locale – While this is optional, if you want to return in any locale other than default, you have to specify the locale.
And below is the output when I run my flow.
Since I specified C3, it returned to 3 places of decimal.
What if I want to return it in any other locale. The below format returns the output with french as the locale.
formatNumber(float(variables('TestVariable')), 'C3', 'fr-FR')
You have to agree, it’s much better than string manipulation.
Hope this helped!
You will also like the below posts
Debajit Dutta
Business Solutions MVP
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.