I am a supporter of St. Joseph's hospice. If you find this site useful or if it helped you, consider a small donation to St. Joseph's, please.

Information on
St. Joseph's

Donation Link

NSig

Significant digits of a number are the digits which contribute to its accuracy - generally these are all digits except leading and trailing zeros. For a more precise definition please see http://en.wikipedia.org/wiki/Significant_digits.

An Excel © worksheet function solution to calculate n significant digits of d:
A1: d
A2: n
Result: =--TEXT(A1,"."&REPT("0",A2)&"E+0")

Example: If you want to show pi with 3 significant digits:

20091118_PB_01_NSig

The corresponding VBA solution:

Function nsig(d As Double, n As Long) As Double
'Returns double with n most significant digits of d.
'nsig = Format(d, "." & String(n, "0") & "E+0")
End Function

Note: I developed this function in 2008 on my own: =--TEXT(A1,"0."&REPT("0",A2-1)&"E+0")
But the version shown above circulated in the web even earlier.

A related function is Num2Str which returns a non-scientific string representation of a given number with with all significant digits and all leading and trailing zeros.