How to calculate this formula and display percentage?

Hi everyone! I have a couple questions.

I’m trying to do a calculation and it looks like this:

Inhale (ex. 30) minus Exhale (ex. 28) divide that by Exhale (ex. 28) and divide that by .1 to get .71

I’m using Firebase for the authentication and the database. I want the user to fill out the inhale and exhale numbers and spit out a percentage when the calculate button is clicked.

Could I please get some help around the right blocks I need to use to make that calculation. If i’m using Firebase for the storage I would use cloud variables correct?

Attached are screenshots for reference.

I don’t understand your math. What is exhale/exhale/.1? Wouldn’t that just be 1/.1 which equals 10?

Can you provide a link to a description of the equation and/or some sample values so I can understand the equation better? I think there may be some missing parentheses.

Does this help? A person would take their measurements during a breathing exercise to get the numbers to input into the inhale and exhale fields.

The calculation is:

Take your inhale number (ex. 30) and subtract from your exhale number (ex. 28). Take the result of that and divide by your exhale number (ex. 28) and then divide by .1 to get 0.71.

Screenshot 2022-12-30 at 4.17.06 PM
Screenshot 2022-12-30 at 4.19.02 PM

Got it. So the left side of the equation should be (I-E)/E)*10.

And then to get a percentage, multiply that result by 100. Or just replace the 10 in the equation with 1000.

I’m not at my computer but I can help you with the blocks later if you still need that.

Thank you! I was able to get the output 0.7142857142857143. What’s the best way to trim that down to just say 71% as the result?

Also - how can I display a a grade like Grade = F if the percentage falls between certain percentages?

The grades are not too hard to do but not something I can explain on my phone.

If you multiply 0.71… by 100 and place that inside a Round block from the Math drawer, you’ll get an integer. Then, optionally, you can use the Join block in the Text drawer to add “%” to the end.

1 Like

Whenever you have time.

Thank you so much for the help! I have it working now.

1 Like

You’re welcome. Your percent—>grade question is typically solved with an if/else if/else if… set of blocks. But it can also be solved with a series of stacked if blocks. Create two variables called percent and grade. Set percent to the value you calculated (such as 71%). Then set up this (I’m using sample values… your actual ranges may be different):

Edit: Oops! I originally had these in the wrong order. It should be:

If percent <= 100 then set grade to A
If percent < 90 then set grade to B
If percent < 80 then set grade to C
If percent < 70 then set grade to D
If percent < 60 then set grade to F

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.