# Calculating results to two significant figures

**URL:** <https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598>\
**Category:** Questions about Thunkable X\
**Created:** [February 24, 2024, 9:13pm UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598 "2024-02-24T21:13:30Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![catherine.jeanesq](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@catherine.jeanesq](https://community.thunkable.com/u/catherine.jeanesq)\
**Post date:** [March 19, 2024, 1:19am UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/21 "2024-03-19T01:19:05Z")

</div>

sorry, I’m not sure what you mean. The issue only comes up when the result of the equation is \<1. In the example I uploaded earlier showing the NaN results, the first one should have been 0.8ml and the second 0.48ml. Any amount that is \>1 works fine. The weight in the example was 4kg (this is calculated on the previous screen then saved as a variable).

---

<div class="post-metadata">

**Author:** ![catherine.jeanesq](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@catherine.jeanesq](https://community.thunkable.com/u/catherine.jeanesq)\
**Post date:** [March 19, 2024, 1:22am UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/22 "2024-03-19T01:22:30Z")

</div>

I previously was trying a different way to calculate it, with this block, but I can’t work out how to get a local variable within the function.

 ![my 2 sf block](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/d/ada7d9fc8b6edfa69acb3e6d645d509be4bfafb1.jpeg)

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [March 19, 2024, 1:31am UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/23 "2024-03-19T01:31:03Z")

</div>

what im trying to say is the error does not jibe with your formula.  
in below, i copied your inputs and your formulas as shown by the red lines.  
i did the same for the other 2, using the formula you have in your block.  
but i got good answers:1.2, 2.7, and 3.1 - not what you expect but i didnt get an error.  
please recheck.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/9/39aea566d8ccf9acc8e27e11f071d055c7b454bc.jpeg)

---

<div class="post-metadata">

**Author:** ![catherine.jeanesq](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@catherine.jeanesq](https://community.thunkable.com/u/catherine.jeanesq)\
**Post date:** [March 19, 2024, 2:57am UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/24 "2024-03-19T02:57:11Z")

</div>

so the weights are not the numbers in the middle column. The weight for all the calculations on this screen is 4kg. The numbers on the left column are doses calculated at 60mg/kg then divided by the drug concentration on the far right i.e. 200mg/ml for the top row. The middle column shows drug dose calculated at 200mg/kg for the same weight (4kg) divided by the same drug concentration.  
Any result that is over 1ml shows up perfectly, it’s the amounts that are \<1ml that show as NaN.

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [March 19, 2024, 4:26pm UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/25 "2024-03-19T16:26:48Z")

</div>

sorry, you will have to discard the solution i proposed. or modify it or get another method.  
i had to use logarithms to do the process - i was getting correct results when using my google sheet model because google sheet maintains a very high precision when computing logs and antilogs. it seems that thunkable only keeps only 6 decimal digits of precision for logs and it affects the numbers between 0 and 1, especially when it approaches zero. i suggest you add if statements in the subroutine to

1. handle a number when its zero (if its zero , skip everything and return zero,
2. another to handle when absolute value is less than 1 - you might just do a simple round or truncate
3. and everything else you can pass to the original subroutine process.  
sorry about that.

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [March 19, 2024, 7:01pm UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/26 "2024-03-19T19:01:40Z")

</div>

can you show me an actual formula (block ad display) that doesnt work?

because i made all my weights 4 as you suggested and used this code

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/8/4853118d09e946755f20ee0f20935826cd7e8c3f.png)

when i pressed the button, i got this  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/b/db064dff4064b3ab3816640ea974927124ed56db.png)

the answers are all good.  
can you do the same code and show me what you got.

---

<div class="post-metadata">

**Author:** ![catherine.jeanesq](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@catherine.jeanesq](https://community.thunkable.com/u/catherine.jeanesq)\
**Post date:** [March 20, 2024, 2:01pm UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/27 "2024-03-20T14:01:32Z")

</div>

I’ve made a different version, it’s not as elegant but it does do the calculation I need. I don’t know how to convert it into a function, at the moment it works as a series of IF statements under each line, but this would massively slow up the app. Any idea how to get this into a function that I could use in a similar way to the above? Thanks  
 ![Screenshot 2024-03-20 135941](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/e/de0d7585ee2afceceb2af6024dec59a2c8792426.png)

 ![Screenshot 2024-03-20 135929](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/b/2b562754aac6b489e841cabd1665540ea3c90d53.png)

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [March 20, 2024, 5:37pm UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/28 "2024-03-20T17:37:00Z")

</div>

i’ll give it a shot - couple hours

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [March 20, 2024, 6:26pm UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/29 "2024-03-20T18:26:00Z")

</div>

can you see if this works for you

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/7/57599d9407af7e00b8c00ffad264a305aa489b82.png)

here’s the link (see Screen 16)  
[https://x.thunkable.com/copy/d5d14c25c58a50bec472d9cbb4f634ed](https://x.thunkable.com/copy/d5d14c25c58a50bec472d9cbb4f634ed)

---

<div class="post-metadata">

**Author:** ![catherine.jeanesq](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@catherine.jeanesq](https://community.thunkable.com/u/catherine.jeanesq)\
**Post date:** [March 24, 2024, 5:19pm UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/30 "2024-03-24T17:19:01Z")

</div>

so the latest block produced a lot of 0’s, but I adapted your earlier block into this and it seems to work perfectly. Thanks for all your help!

 ![final sig dig block](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/5/b528d0a2d4f7d2da78034e41a727fcab05db7bb7.jpeg)

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [March 25, 2024, 2:14am UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/31 "2024-03-25T02:14:56Z")

</div>

super!

---

<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:** [June 23, 2024, 2:15am UTC](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598/32 "2024-06-23T02:15:30Z")

</div>

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

[Previous page](https://community.thunkable.com/t/calculating-results-to-two-significant-figures/2854598.md?page=1)
