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).
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.
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.
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.
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
- handle a number when its zero (if its zero , skip everything and return zero,
- another to handle when absolute value is less than 1 - you might just do a simple round or truncate
- and everything else you can pass to the original subroutine process.
sorry about that.
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
when i pressed the button, i got this
the answers are all good.
can you do the same code and show me what you got.
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
i’ll give it a shot - couple hours
can you see if this works for you
here’s the link (see Screen 16)
https://x.thunkable.com/copy/d5d14c25c58a50bec472d9cbb4f634ed
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!
super!
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.