Significant figures/ significant digits

What about with decimal places e.g. 23.7890 ? (which should come out as 24)

Or did you really want scientific notation?
7.03E--2

image

I don't remember where I got this.

There is a comment that it will fail on 0 input, so it needs work.

yes that's it

Ideally it needs to cover anything from 0.01 to 10,000+. I should be able to use an IF statement to sort if the value is <= 1 if needed.
How to I get this function?
image

math.aia (50.5 KB)
or you can drag the functions from my prior post directly into your blocks editor window.

If you mean the Do It, it is a feature of the Companion.

I'm trying to do the sig figs for each of these calculations. Is there a way to do this, or should I arrange this in a different way?
Thanks!

That's why I coded the calculations as a value function.

Code half a dozen calls to that function and insert them in stream just before the labels.

like this? Do I need to alter the call log10? Sorry, very new at this!

It is not pretty but this seems to work. Works with positive numbers, but easily modified to handle negative numbers. If nothing else, it demonstrates and extols the ability of AI2 to treat numbers as strings and strings as numbers. Returns integers from 0 - 99 as entered. The blocks are draggable when viewed full size

sigNum.aia (6.4 KB)

You need to copy in the log10 value procedure too because I call it from my procedure.

It's in my prior post or in my math.aia

AI2 lacks its own log10 block.

I have previously done this using a set of If-else statements, but have had to input one per calculation (there are about 80 calculations in the app) so this has slowed down the app so much it is almost unusable. Is there any way to covert this set of if-else statements into a procedure that would work for each calculation? Thanks!

Have you read
http://www.appinventor.org/bookChapters/chapter21.pdf
from the free online book
http://www.appinventor.org/book2
from

yet?

Read it all the way through, to see how to make and call procedures.

Also, you don't need to test for both ends of each range in your if/then/elseif ladder, if you test in strict ascending or descending order.

You could test
if x > the biggest boundary then ...
else if x > the next biggest boundary then ...
elseif x > the next boundary down then ...
...

This works because the elseif triggers the first matching range, and none others.

You would save half the comparisons.

Did you try my procedure?

Hi, yes I have tried it today and so far everything seems great, thanks!

1 Like

Hi, the code is working great, but occasionally I am getting numbers multiplied by 100, can't work out why. Do you mind taking a look? Thanks!


We are working without your code (.aia) and without any word on which values come out wrong, and without the base data.

That makes it hard to debug.

Sorry, have uploaded it now. Thanks, I really appreciate your help!
Cetacean_calculations_and_formulary.aia (57.1 KB)

Which values are coming out wrong?

You appear to divide most "weights" by 100, but some you do not, is this the issue ?