Significant figures/ significant digits

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
from the free online book


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 ?

Here is an experiment you can try to see if the problem comes from the significant2 value procedure:

This is the procedure you currently use.
The idea is to replace it with another procedure that just returns its input, unchanged.
If that eliminates the 100 factor problem, the problem is in the procedure.
If it does not eliminate the 100 factor problem, the problem is in one or more of the calls to the procedure.

This is a delicate operation.
We can't change the procedure name or its parameter, or else all the call blocks will puke parameters all over the place.

Gently reach inside the procedure and yank out its local variable value block, leaving the procedure block empty but with its original name and parameter...

Plug the empty procedure block with the value of its input parameter...
blocks (5)

Now run your tests.

To close up the patient after the tests, reverse the process...
remove the value block
re-insert the local variable block

I've tested it as you said, it was fine with the procedure just set to the input parameter, but when I put the full procedure back in, it produces the error again. It's not all the time, some of the results come out normal, and some will randomly seem to change, it seems to depend on what species and what weight I input on the previous screen. Different weights for the same species also through up the error as well.

If you want to proceed with the procedure you are currently using, help the author of that procedure by providing the numeric values that produce the problem.

Alternatively, use my procedure from

(pulling in both parts).

Hi, I have some examples:
Harbour Porpoise (UK): 1.5m = 44kg is fine; 1.2m gives an error on the sixth calculation down on the right (phenobarb g per m 500mg/ml dose to).
Beluga whale: works fine on 3m = 365kg, fine on 4m, fine on 2.3m, but on 1.2m there is an error on the sixth calculation down on the right (phenobarb g per m 500mg/ml dose to).
Humpback whale: 17m = 70242kg error on fourth down on the left and right (phenobarb g per m 200mg/ml, dose from and to), and error on sixth calculation down on the left (phenobarb g per m 500mg/ml dose from). If 19m = 97520kg error on fifth calculation down on left (phenobarb 300ml/ml g per m dose from).

It seems very random, I really can't understand it.

Sorry. Do not know where to look in your blocks in order to see what calculations you are doing...

Please show the specific calculation for the displayed "incorrect" value returned.

I have tested all the numbers you show above, the procedure converts all of these correctly to two significant numbers

OK, believe I found the problem, when a number being added has a .0 at the end, e.g. 216.0, the procedure doesn't like it (wasn't a condition I expected/factored in)

Replace the significant2 procedure with this one, any better ?