Math Help - Formula not working

Here’s the link to the project:

I am trying to get a formula that works in Excel to work in Thunkable. I have put both formulas, in the comments, in the Blocks section.

The formulas are:
=180/PI() * ACOS(COS(PSA to PAP * PI()/13.5)/SIN(Pin to PAP * PI()/13.5))
=180/PI() * ASIN (SIN(Pin Buffer * PI()/13.5)/SIN(Pin to PAP * PI()/13.5))

User inputs are as follows
Pin to PAP 4
PSA to PAP 4
Pin Buffer 2

The result returned should be 42 x 4 x 34.

The result I get is 1 x 4 x 2.

I’m stuck, any help would be greatly appreciated.
Thank You. :sunglasses:

1 Like

When I viewed your project, the first formula was set to 180 / π * ASIN(SIN(…

But even after switching it to 180 / π * ACOS(COS(… it still doesn’t return the expected values.

It may matter that Thunkable is expecting degree values for trig functions.

Can you provide a link to a website that shows those formulas? I find it a little hard to read in the current format. Edit: nevermind. I found a website but it’s not any better formatted than what you shared. And I also get 42 for the first result as soon as I paste the formula into Excel. So yeah, it’s a matter of parsing what you put together. :wink:

1 Like

Having so many nested blocks, it is amost impossible for my little brain to figure out the issue. Whenever I have a process with more than 2 nested blocks, I will create a temporary variable and perform the calculation one operation at a time. I will also update a label to show the result of each step so I can see how where the calculation is breaking down. Something like this:

Good luck and happy Thunking!


I’d agree with @drted and was going to suggest the same. It’s a little extra work at the beginning but much easier to troubleshoot and modify later.

Also, I think the problem with your formula in Thunkable is that you have a much larger/longer denominator than the original functions suggests. So instead of 180/π * …, you have 180/(π * …)

Here’s where I’m at now. I broke the formula down into parts and gave each part its own variable, thank you for the suggestion. It does make it easier to troubleshoot. What I am finding out is the SIN function does not return the correct value. If I do SIN(.47) to 2 decimal places it should return the value 0.45, but when I use the sin block and put the value in of .47 it returns 0.01. So I’m starting to think that the sin block itself is mis-calculating. Does that make sense?

Try splitting out the SIN for the Rounding to 2 decimal places. A few weeks ago I discovered that the …with…decimal places block returns a string, not a number. Map crashes when adding markers from data source.

Save the rounding to the final display step.

1 Like

I tried this and it still does not return the correct value. For SIN(.47) thunkable returns 0.0082029554875217 without using Rounding.

Sounds like a Radians vs. Degrees problem.

I sent a PM to Thunkable to see what they can find out. I’ll post the reply when I receive it. :sunglasses:

1 Like

You need to convert from radians to degrees.

Screen Shot 2020-10-21 at 7.57.06 AM


Absolutely Brilliant !!! Thank You !!!
The sin and cos blocks now return the correct values.
I tried doing the same with the asin and acos blocks and still received the wrong result.
asin(.56) is .59, but thunkable block returns 34.06
acos(.75) is .72, but thunkable block returns 41.41

Any thoughts on how to correct this? :thinking:

You’re welcome!

No… I can’t make heads or tails of the asin function results I’m seeing.

If you REALLY need it, you might try bypassing thunkable and using a 3rd party web API. It is DEFINITELY a more challenging Thunkable project, but it is an option.

A quick google search found this API that might do what you need

Hi guys, I know I’m like a year late but I got it to work! @drted’s api solution was great but network here in my country is quite slow and it would be a pain on bad days and even worse for a batch requests if I had to use a for loop. It works in degrees as of testing and you can see the blocks below as well a sample test I did. I double checked with radians in excel and it returned the same answer.



The link to the project is here. I would think everyone on this thread figured it out by now but if you didn’t, or if it’s someone like me who saw this but couldn’t get the acos to work as intended, hope this helps! Now we should be able to rip the coordinates from wherever (e.g api response) and plug them right into the function on the client side.

For anyone who want to know more information, this method uses the haversine formula with the respective formulae below:
d = r * ( (pi/180) * acos( (sin(lat1) * sin(lat2)) + cos(lat1) * cos(lat2) * cos(lng2 - lng1) ) )

RADIANS ( e.g lat radian = lat/(180/pi) )
d = r * acos( (sin(lat1) * sin(lat2)) + cos(lat1) * cos(lat2) * cos(lng2 - lng1) )

“r” is the radius of the earth in the units you want (miles, metres, kilometres…) so you can use whichever you prefer, I just ripped them straight from google in the example.

Edits Summary


  1. Added the project link
  2. Forgot to add that multiplying the acos by pi/180 allows us to convert this to radians for the formula to work if your acos/asin/atan is in degrees


  1. Added that it is the haversine formula
  2. Spelling errors

Nice! Thanks for sharing all that. Is this the Haversine formula or something else?


thunakable is set up to use degrees when dealing with trigonometry.
so asin(0.56) is computed by thunkable as 34.06 , which is correct - the answer is 34.06 degrees.
if you want the result in radians, you need a degrees_to_radians function similar to the one mady by @tatiang

this is the result for converting asin(0.56):


@tatiang You are correct, it is the haversine formula. I will edit my comment to state that clearly.