# How to calculate this formula and display percentage?

**URL:** <https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065>\
**Category:** Questions about Thunkable X\
**Created:** [December 30, 2022, 8:17pm UTC](https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065 "2022-12-30T20:17:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikew1944](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mikew1944/32/143983_2.png) [@mikew1944](https://community.thunkable.com/u/mikew1944)\
**Post date:** [December 30, 2022, 8:17pm UTC](https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065/1 "2022-12-30T20:17:44Z")

</div>

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.

 ![Screenshot 2022-12-30 at 3.13.49 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/e/7e29099dcc36afc470f119af2320ad5053649501.png)

 ![Screenshot 2022-12-30 at 3.16.21 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/6/0674d319ac4b5499d558036c0a8aca0a78930a6b.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [December 30, 2022, 9:07pm UTC](https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065/2 "2022-12-30T21:07:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikew1944](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mikew1944/32/143983_2.png) [@mikew1944](https://community.thunkable.com/u/mikew1944)\
**Post date:** [December 30, 2022, 9:24pm UTC](https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065/3 "2022-12-30T21:24:13Z")

</div>

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](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/8/d8cf03e4d3f9c8a9c0651f90b7c913a7d9ced82f.png)  
 ![Screenshot 2022-12-30 at 4.19.02 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/c/9cfe85cbd7f46cef52552f769944c2ac4c48fc22.png)

 ![Screenshot 2022-12-30 at 4.18.10 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/d/bd84baaa060af7672f62b19df727d1d3c8291a97.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [December 31, 2022, 1:19am UTC](https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065/4 "2022-12-31T01:19:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikew1944](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mikew1944/32/143983_2.png) [@mikew1944](https://community.thunkable.com/u/mikew1944)\
**Post date:** [December 31, 2022, 2:01am UTC](https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065/5 "2022-12-31T02:01:42Z")

</div>

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?

 ![Screenshot 2022-12-30 at 8.58.54 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/9/c9d9a63a5a694e5044de70e3c1767bb36d6166e0.png)  
 ![Screenshot 2022-12-30 at 9.00.13 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/8/d8aeaa538f9e350b1e477b3e3414c13da8ef2b3e.png)  
 ![Screenshot 2022-12-30 at 9.11.43 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/b/1b8b1c7a2586d75e2db2d20e829fe30355f1039c.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [December 31, 2022, 2:49am UTC](https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065/6 "2022-12-31T02:49:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikew1944](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mikew1944/32/143983_2.png) [@mikew1944](https://community.thunkable.com/u/mikew1944)\
**Post date:** [December 31, 2022, 3:01am UTC](https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065/7 "2022-12-31T03:01:40Z")

</div>

Whenever you have time.

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

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [December 31, 2022, 7:03am UTC](https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065/8 "2022-12-31T07:03:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [March 31, 2023, 7:03am UTC](https://community.thunkable.com/t/how-to-calculate-this-formula-and-display-percentage/2199065/9 "2023-03-31T07:03:53Z")

</div>

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