Skip to content

Function to determine number of significant figures (e.g. in answer) #61

@FloMiLe

Description

@FloMiLe

Description of proposed feature

I think it would be helpful to have a function that returns the number of significant figures of some given number, e.g. an answer. This should probably be done after converting to a string in order to catch trailing zeros.

As significant figures convey meaning in physics, I would like to attribute points for rounding numeric answers to a meaningful number of significant figures.

How can the new feature be used?

Say the function was called numsigfig, then it should be used as:

numsigfig(1234) => 4
numsigfig(1.234) => 4
numsigfig(0200) => 3
numsigfig(0.200) => 3

Additional comments

I currently use the following code to determine the number of significant figures nSigFigAns in an answer:

origAns = _0;

expAns = floor( log10(abs(origAns)));
mantAns = origAns / ( 10**( expAns ));
nSigFigAns = 1;
for (i:[0:6]) {
    shiftedNum = round( 10**(i) * abs(mantAns) , 6 );
    divTest = round( shiftedNum - floor(shiftedNum) , 6);
    nSigFigAns = ( divTest > 1e-5 ) ? nSigFigAns+1 : nSigFigAns ;
}

I don't think, it would be doable using Formula's current string functions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions