Function Repository Resource:

# SignificantDigits

Determine the number of significant digits in a number

Contributed by: Wolfram Chemistry Team
 ResourceFunction["SignificantDigits"][x] gives the number of significant digits in x. ResourceFunction["SignificantDigits"][{x1,x2,…}] gives the list of results for each xi.

## Details and Options

All nonzero digits and zeros between nonzero digits are significant digits.
Zeros employed to position the decimal are not significant.
Zeros to the right of the decimal that are also right of the last nonzero digit are significant digits.
Trailing zeros in Integer numbers are not significant by default.
ResourceFunction["SignificantDigits"] automatically threads over lists.
Setting the option "DigitDecompose"True makes ResourceFunction["SignificantDigits"] return the number of leading zeros, significant digits and trailing zeros for the digits before and after the decimal as an Association of six Integer numbers. Significant trailing zeros are returned as negative values.
Setting the option "ExactNumber"True makes ResourceFunction["SignificantDigits"] treat Integer numbers as exact numbers.
Setting the option "TrimLeadingZeros"True makes ResourceFunction["SignificantDigits"] trim the leading zeros before processing.
Setting the option "UseTrailingZeros"True makes ResourceFunction["SignificantDigits"] treat trailing zeros in Integer numbers as significant.
ResourceFunction["SignificantDigits"] can also accept a string representing a number, such as "1.234".

## Examples

### Basic Examples (5)

Find the number of significant digits in a Real number:

 In[1]:=
 Out[1]=

Find the number of significant digits in a String representing a number:

 In[2]:=
 Out[2]=

Find the number of significant digits in an Integer number:

 In[3]:=
 Out[3]=

Find the number of significant digits in an exact Real number represented as a Rational number:

 In[4]:=
 Out[4]=

Determine the number of significant digits for a List of values:

 In[5]:=
 Out[5]=

### Scope (8)

#### Numerical Precision (1)

Accuracy and Precision information in arbitrary-precision numbers is obeyed:

 In[6]:=
 Out[6]=

#### String Formats (5)

AccountingForm is supported:

 In[7]:=
 Out[7]=

DecimalForm and PercentForm are supported:

 In[8]:=
 Out[8]=

FortranForm and CForm are supported:

 In[9]:=
 Out[9]=

ISO expanded uncertainty is supported:

 In[10]:=
 Out[10]=

ScientificForm is supported:

 In[11]:=
 Out[11]=

#### Uncertainty (1)

Uncertainty in Around and VectorAround is obeyed:

 In[12]:=
 Out[12]=
 In[13]:=
 Out[13]=

#### Units (1)

Quantity, QuantityArray and MixedMagnitude values with units are supported:

 In[14]:=
 Out[14]=
 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=

### Options (4)

#### DigitDecompose (1)

The number of leading zeros, significant digits and trailing zeros before and after the decimal can be returned as an Association:

 In[17]:=
 Out[17]=

#### ExactNumber (1)

Integer numbers can be treated as exact numbers:

 In[18]:=
 Out[18]=

Leading zeros in a String of digits can be trimmed before processing:

 In[19]:=
 Out[19]=
 In[20]:=
 Out[20]=

#### UseTrailingZeros (1)

Trailing zeros in Integer numbers can be treated as significant:

 In[21]:=
 Out[21]=
 In[22]:=
 Out[22]=

### Applications (1)

Do significant digit-compliant subtraction:

 In[23]:=
 Out[23]=
 In[24]:=
 In[25]:=
 Out[25]=

### Properties and Relations (5)

Trailing zeros in Integer numbers are always insignificant by default:

 In[26]:=
 Out[26]=

Enabling exact numbers also enables "UseTrailingZeros":

 In[27]:=
 Out[27]=

Whitespace and commas in String values are ignored:

 In[28]:=
 Out[28]=

String values without numbers in supported formats fail:

 In[29]:=
 Out[29]=

SignificantDigits output for Integer numbers is related to IntegerLength and IntegerExponent results:

 In[30]:=
 Out[31]=

SignificantDigits output for arbitrary-precision numbers is related to Precision and Accuracy results:

 In[32]:=
 Out[32]=
 In[33]:=
 Out[33]=

### Possible Issues (4)

Around and VectorAround may produce unexpected results:

 In[34]:=
 Out[34]=

MachinePrecision numbers may produce unexpected results after computations:

 In[35]:=
 Out[35]=
 In[36]:=
 Out[36]=
 In[37]:=
 Out[37]=

Scientific notation containing a decimal implies a Real number and may produce unexpected results:

 In[38]:=
 Out[38]=

Trailing zeros in Real numbers are dropped unless specified using SetPrecision or SetAccuracy:

 In[39]:=
 Out[39]=

"UseTrailingZeros" is required to process an Integer number containing trailing zeros and a truncating Precision:

 In[40]:=
 Out[40]=
 In[41]:=
 Out[41]=

### Neat Examples (1)

Compute a significant digit-compliant molecular mass from an element tally:

 In[42]:=
 In[43]:=
 Out[43]=

## Publisher

Wolfram Chemistry Team

## Version History

• 1.0.0 – 03 December 2019