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

decimal place

Is it possible to limit a float to 2 decimal place?

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Super User
Super User

Re: decimal place

Hi @sfoerst

 

Limit the float variable no, but you can use an action to transform cutting the others decimals places.

 

The expression to do this is :

 

if the float value is in a variable : 

 

substring(string(variables('VARIABLE_NAME')),0,add(indexof(string(variables('VARIABLE_NAME')),'.'),3))

 

also, if is in a action:

 

substring(actionOutputs('ACTION_NAME'),0,add(indexof(actionOutputs('ACTION_NAME'),'.'),3))

 

In this fuction the is the count of decimal places plus the dot place.

 

If you need more help, post here.

 

Hope Have Helped,

 

Gustavo Moraes


Did I answer your question? Mark my post as a solution!

Gustavo Moraes, o astronauta brasileiro do Flow!


View solution in original post

Super User
Super User

Re: decimal place

Hi @sfoerst you need to click inside dynamic content to use expression and put that function inside the red square,

like the print below:

Flow 2.png

 

 OBS: I see the text inside variable is the float value, in the snippet that i post you need to put the Variable Action name, if you have direct value, can remove the literal text "variable"

 

Best Regards,

 

Gustvo Moraes


Did I answer your question? Mark my post as a solution!

Gustavo Moraes, o astronauta brasileiro do Flow!


View solution in original post

15 REPLIES 15
Highlighted
Super User
Super User

Re: decimal place

Hi @sfoerst

 

Limit the float variable no, but you can use an action to transform cutting the others decimals places.

 

The expression to do this is :

 

if the float value is in a variable : 

 

substring(string(variables('VARIABLE_NAME')),0,add(indexof(string(variables('VARIABLE_NAME')),'.'),3))

 

also, if is in a action:

 

substring(actionOutputs('ACTION_NAME'),0,add(indexof(actionOutputs('ACTION_NAME'),'.'),3))

 

In this fuction the is the count of decimal places plus the dot place.

 

If you need more help, post here.

 

Hope Have Helped,

 

Gustavo Moraes


Did I answer your question? Mark my post as a solution!

Gustavo Moraes, o astronauta brasileiro do Flow!


View solution in original post

sfoerst
Level: Powered On

Re: decimal place

Where do i have to put in that code snipped?

I have a variable as a string. 

 

Thanks

Super User
Super User

Re: decimal place

Hi @sfoerst, i recommend you to use a 'Compose' action.

Look the images:

 

 

Flow.pngHow i did

 After yoiu can use this compose to do your flow.

 

 

Flow 1.pngResult

 Hope Have Helped,

 

Gustavo Moraes

 

 


Did I answer your question? Mark my post as a solution!

Gustavo Moraes, o astronauta brasileiro do Flow!


sfoerst
Level: Powered On

Re: decimal place

Unbenannt.PNG

almost

sfoerst
Level: Powered On

Re: decimal place

substring(string(variables('4.68750000000000')),0,add(indexof(string(variables('4.68750000000000')),'.'),3))sub

Super User
Super User

Re: decimal place

Hi @sfoerst you need to click inside dynamic content to use expression and put that function inside the red square,

like the print below:

Flow 2.png

 

 OBS: I see the text inside variable is the float value, in the snippet that i post you need to put the Variable Action name, if you have direct value, can remove the literal text "variable"

 

Best Regards,

 

Gustvo Moraes


Did I answer your question? Mark my post as a solution!

Gustavo Moraes, o astronauta brasileiro do Flow!


View solution in original post

sfoerst
Level: Powered On

Re: decimal place

Thank you it works!!!

BG22
Level: Powered On

Re: decimal place

@gamoraes You are my hero and if you were present I would buy you lunch! THANK YOU!!

PatUmaknow
Level: Powered On

Re: decimal place

Hi,

To overcome the problem of having a decimal number with only one decimal, simply add an insignificant number to it, like 0,00001. 

This way you automatically always have more that 2 decimals.

Here is the formula:

substring(string(add(triggerBody()['number'],0.000001)),0,add(indexof(string(add(triggerBody()['number'],0.000001)),'.'),3))
LEARN_IT
Level: Powered On

Re: decimal place

This method does not work if You run numbers like. 390.00 or 290.00. I'm getting results 39 ir 29

Here is my formula: 

substring(string(variables('TotalExpense')),0,add(indexof(string(variables('TotalExpense')),'.'),3))
Super User
Super User

Re: decimal place

Hi @LEARN_IT, the problem with your expression is in red, you need to put the length of decimal places(in your case 2)

 

substring(string(outputs('Compose')),0,add(indexof(string(outputs('Compose')),'.'),3))
 
The correct function to remove decimal with 2 places are
 
substring(string(outputs('Compose')),0,add(indexof(string(outputs('Compose')),'.'),2))
 

Did I answer your question? Mark my post as a solution!

Gustavo Moraes, o astronauta brasileiro do Flow!


Murderbot
Level: Powered On

Re: decimal place

One note here, it may be wise to convert it back into a float by adding float() as the last step of the formula.

 

float(substring(string(outputs('Get_Running_Total')),0,add(indexof(string(outputs('Get_Running_Total')),'.'),3)))

 

degvalentine
Level 8

Re: decimal place

I posted a solution that rounds a float to hundreths on another thread. The solutions above truncate.

nmccool
Level: Powered On

Re: decimal place

the decimal solution worked for me, BUT do you also have a solution for adding the comma in appropriate places?

degvalentine
Level 8

Re: decimal place

Yup. See my post here. My 2nd post on that thread has the more robust, expanded version.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 110 members 4,198 guests
Recent signins:
Please welcome our newest community members: