Hello everyone and welcome to my blog. In my blog today, I am going to discuss on how to round off numbers in Power Automate flows.
Through my blog I share interesting tips and discuss on latest releases of Microsoft.NET technologies, Dynamics 365 and Power Platform, SharePoint and Client scripting libraries. Please subscribe to my blog to stay updated.
As surprising it may be, as of the time of writing this blog, Power automate does not have any inbuilt function to round off numbers. However we have the formatNumber function which come very close to provide the desired outcome.
Let’s get started. Let’s start our example with the number – 3456.45. To round off, I will use the expression formatNumber(‘<number value>’, ‘#0’)
And below is the output.
As you can see, the number has been rounded down to the nearest integer. If I now try the same expression with another value of 3456.65, the output will be rounded off to 3457.
So formatNumber function will automatically round the decimal value to the nearest integer depending on whether the decimal part is greater or less than 5.
That’s great. So our requirement to round off is achieved. But how about explicit requirement like ROUNDDOWN irrespective of whether the decimal point is greater than 5 or not?
If you think logically, to always ROUNDDOWN a number, we just need substract the decimal part from the number. Precisely below logic.
ROUNDDOWN Number = Original Number - Decimal part of the original number
In Power Automate, the expression boils down to below.
//variables('varX') is my original number
sub(variables('varX'), mod(variables('varX'), 1))
And below is the output. mod function returns are remainder of the division.
How about ROUNDUP then? Precisely the below logic will give you the expected result similar to ROUNDUP.
ROUNDUP Number = ( Original number - Decimal part of original number) + 1
Below is the Power Automate expression to do the same.
add(sub(variables('varX'), mod(variables('varX'), 1)),1)
Well, now you have the equivalent of ROUND, ROUNDUP and ROUNDDOWN in Power Automate. Hope Microsoft introduce a function soon to do this but till then, this post should get your requirement sorted.
I hope this helped. If you have liked the post and if this post has helped you, please subscribe to my blog.
Debajit Dutta
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.