Calculating results to two significant figures

I am trying to get my app to calculate results to significant figures. Does anyone know how to go about doing this?

Thanks!

Do you mean like rounding to a certain decimal value? If so, would this block do what you need? Math - Thunkable Docs

Not exactly. With rounding to two decimal places 210.988098 would become 210.99, whereas with two significant figures it would become 210. I don’t know if there is a built in option with Thunkable to do this.

No, there isn’t. But I’m guessing there is a javascript function or Google Sheets formula that you can use externally and then get the resulting data into Thunkable.

I haven’t tried it but what happen rounding to 3 decimal places and then round the result to 2 decimal places ? Probably the same :rofl:

Provide another example of rounding to better understand.

this works. (the rounding rule is simple though , if the fraction ends in 5 or more, round it up)

example using 12.344 (rounded to 2 places)
image

example using 12.345 (rounded to 2 places)
image

if you don’t want to show the intermediate field (ie. label17), set the font to white or set the field to invisible.

I was thinking also about to combine together round with decimal and round up/down or to write a code to fit your round rules

I had to Google it but significant figures are very different from rounding.

Wow I never meet this kind of rules.

So If I understand well the rules, the two significant figures in this example (only because we don’t know the operation that generated this number ) are 21 (? I’m not sure) so we have to look at the extra number (the first after the last significant figures) and it is a zero ( < 5) so the number doesn’t change 21 .
Result 210

  • If the extra number is bigger than 5 you have to add +1
  • If the extra number is a 5 :
    •If the next number is bigger than zero then add+1
    •If the next numbers are only zero we have to look at
    the number before the extra number
    + if even not change
    + if odd then add +1

:man_facepalming:t2:

i stand corrected. significant digits are different from rounding.

i’ve written a function to return significant_digits and a demo program to call it.

here are some sample screen shots
image

image

if the input is negative (it has to save the sign, do its thing on the absolute value then re-sign it)
image

the code blocks are pictured here

here’s the link to the program (please use SCREEN 16)
https://x.thunkable.com/copy/dfdc3b1fab18674b3abccf8146152a24

disclaimer: i’m not using the esoteric rules of rounding - i’m using the rule - round up if digit is 5 or more

1 Like

Thank you so much for all your help with this! It seems to be working really well!

are you referriing to my suggestion? if you think it answers your question, please mark this thread Solved. thank you.

Hi, I’m having some trouble with the code if the number is <1. Do you mind having a look? Thanks

what’s wrong? can you provide the input, the actual output from the program and your expected output?

It just replies NaN, then when I calculate the number myself, it only seems to do this when the result is <1. Could I add an if statement into the function so if the number is <1 I can do round to 2 decimal places? Would that work?

sorry about that - it couldn’t handle when number is 1 followed by any number of zeroes. my bad.
here’s the new code. the routine now has an IF block to test for that condition.
image

here’s a picture of the whole program

and here’s the link (see screen 16)
https://x.thunkable.com/copy/c899b3f88ad6558816b8512bacaca324

I’m still having issues with when the number is <=0.99. Any numbers above this work perfectly, but not anything less than 1. Do you mind taking a look? Thanks!


i took th weights (4,2.7,1.6) from below
image

and plugged them into your first 3 formulas
image

into this debugging block

(which has the same formulas as your first 3 computations).

and i got this result
image

please recheck if you applied my fix the same way , also check if your factors (numerator,denominator) are correct - the formulas don’t seem to agree with the display (esp. mg/kg).

i suggest you make ANOTHER routine with 4 parameters: #of+digits, weight, w_mult, w_divsr and return a formula that uses sigdig.

can you display you version of sigdig?

Hi, here’s my version of sigdig:

can you temporarily change your button block (save the old contents) and make it look like the one i made above. and give me the results.

can you give me the actual values you are trying that are giving you problems?