Enter a number below to determine its significant figures and understand the rules applied.
function calculateSignificantFigures() {
var numberString = document.getElementById("numberInput").value.trim();
var resultDiv = document.getElementById("significantFiguresResult");
var explanation = "";
var sigFigs = 0;
if (numberString === "") {
resultDiv.innerHTML = "Please enter a number.";
return;
}
// Handle scientific notation (e.g., 1.23e-4 or 1.23 x 10^4)
var scientificMatch = numberString.match(/^([+-]?\d*\.?\d+)(?:[eE][+-]?\d+|[xX]\s*10\^?[+-]?\d+)?$/);
if (scientificMatch) {
numberString = scientificMatch[1]; // Use only the mantissa for sig fig counting
explanation += "
The number is in scientific notation. We count significant figures only from the mantissa (" + numberString + ").
";
}
// Remove any non-numeric characters except for '.' and '-'
var cleanedString = numberString.replace(/[^0-9.-]/g, ");
// Check if the cleaned string is a valid number format
if (!/^[+-]?(\d*\.?\d+)$/.test(cleanedString)) {
resultDiv.innerHTML = "Invalid input. Please enter a valid number.";
return;
}
var hasDecimal = cleanedString.includes('.');
var tempString = cleanedString;
// Remove leading zeros for counting purposes, but keep track of original string for explanation
var originalTempString = tempString;
tempString = tempString.replace(/^[+-]?0+/, "); // Remove leading zeros (e.g., 0.00123 -> .123, 0123 -> 123)
// If after removing leading zeros, it's just a decimal point followed by digits (e.g., .123), add a leading zero back for parsing
if (tempString.startsWith('.')) {
tempString = '0' + tempString;
}
// If the original number was just "0" or "0.0"
if (cleanedString === "0" || cleanedString === "-0") {
sigFigs = 1;
explanation += "
The number is zero. A single zero is considered to have one significant figure.
The number is zero with a decimal point. The significant figures are counted from the first non-zero digit to the last, including trailing zeros after the decimal. In this case, only the zeros after the decimal are significant.
";
} else {
// Rule 1: All non-zero digits are significant.
// Rule 2: Zeros between non-zero digits are significant.
// Rule 3: Leading zeros (before non-zero digits) are NOT significant.
// Rule 4: Trailing zeros are significant ONLY if the number contains a decimal point.
// Rule 5: Trailing zeros in a number without a decimal point are ambiguous; we assume they are NOT significant unless a decimal point is present.
var numDigits = 0;
var firstNonZeroFound = false;
var lastNonZeroIndex = -1;
var firstNonZeroIndex = -1;
for (var i = 0; i < cleanedString.length; i++) {
var char = cleanedString[i];
if (char === '.' || char === '+' || char === '-') {
continue;
}
if (char !== '0') {
if (!firstNonZeroFound) {
firstNonZeroFound = true;
firstNonZeroIndex = i;
}
lastNonZeroIndex = i;
}
}
if (firstNonZeroIndex === -1) { // This means the number was all zeros or just a decimal point
if (hasDecimal) { // e.g., "0.00"
sigFigs = cleanedString.length – (cleanedString.startsWith('-') ? 1 : 0) – 1; // -1 for decimal point
if (sigFigs < 1) sigFigs = 1; // At least one sig fig for 0.0
explanation += "
The number consists only of zeros and a decimal point. All zeros after the decimal are significant.
The number is zero. A single zero is considered to have one significant figure.
";
}
} else {
// Count digits from the first non-zero to the last non-zero
for (var i = firstNonZeroIndex; i <= lastNonZeroIndex; i++) {
var char = cleanedString[i];
if (char !== '.') {
sigFigs++;
}
}
explanation += "
All non-zero digits (" + cleanedString.substring(firstNonZeroIndex, lastNonZeroIndex + 1).replace(/\./g, ") + ") are significant.
Leading zeros (e.g., " + cleanedString.substring(0, firstNonZeroIndex).replace(/[+-]/g, ") + ") before the first non-zero digit are NOT significant.
";
}
// Handle trailing zeros
if (hasDecimal) {
// If there's a decimal, all trailing zeros are significant
var trailingZerosCount = 0;
for (var i = cleanedString.length – 1; i > lastNonZeroIndex; i–) {
if (cleanedString[i] === '0') {
trailingZerosCount++;
} else {
break; // Stop if we hit a non-zero or decimal
}
}
sigFigs += trailingZerosCount;
if (trailingZerosCount > 0) {
explanation += "
Since the number contains a decimal point, all trailing zeros (" + cleanedString.substring(cleanedString.length – trailingZerosCount) + ") are significant.
";
}
} else {
// No decimal point: trailing zeros are NOT significant
var trailingZeros = 0;
for (var i = cleanedString.length – 1; i > lastNonZeroIndex; i–) {
if (cleanedString[i] === '0') {
trailingZeros++;
} else {
break;
}
}
if (trailingZeros > 0) {
explanation += "
The number does NOT contain a decimal point, so trailing zeros (" + cleanedString.substring(cleanedString.length – trailingZeros) + ") are generally considered NOT significant (ambiguous without further context).
";
}
}
}
}
resultDiv.innerHTML = "
Results:
" +
"The number " + numberString + " has " + sigFigs + " significant figure(s)." +
"
Significant figures (often called sig figs) are crucial in scientific and engineering fields because they convey the precision of a measurement. When you record a measurement, the number of significant figures tells you how precisely that measurement was made. It's not just about the number itself, but about the reliability of the digits.
Why are Significant Figures Important?
Precision: They indicate the precision of a measuring instrument. A ruler that measures to the nearest millimeter will yield measurements with more significant figures than one that measures only to the nearest centimeter.
Accuracy: They help avoid misrepresenting the accuracy of calculations. When you perform calculations with measured values, the result should not imply greater precision than the least precise measurement used.
Communication: They provide a standardized way to communicate the reliability of data to others.
Rules for Counting Significant Figures
Here are the generally accepted rules for determining the number of significant figures in a given number:
Non-zero digits are always significant.
Example: 2345 has 4 significant figures.
Example: 1.23 has 3 significant figures.
Zeros between non-zero digits are significant. These are sometimes called "sandwich zeros" or "captive zeros."
Example: 1005 has 4 significant figures.
Example: 2.03 has 3 significant figures.
Leading zeros (zeros before non-zero digits) are NOT significant. These zeros merely indicate the position of the decimal point.
Example: 0.0025 has 2 significant figures (the 2 and the 5).
Example: 0.123 has 3 significant figures (the 1, 2, and 3).
Trailing zeros (zeros at the end of the number) are significant ONLY if the number contains a decimal point.
Example: 12.00 has 4 significant figures (the 1, 2, and both zeros after the decimal).
Example: 120. (with a decimal point) has 3 significant figures.
Example: 1200.0 has 5 significant figures.
Trailing zeros in a number without a decimal point are generally NOT significant. These zeros are often placeholders.
Example: 1200 has 2 significant figures (the 1 and the 2). The zeros are not significant.
Example: 5000 has 1 significant figure (the 5).
Note: This rule can be ambiguous. To clarify, scientific notation is often used (e.g., 1.20 x 10^3 clearly indicates 3 significant figures for 1200).
Exact numbers have an infinite number of significant figures. These include numbers obtained by counting (e.g., 12 eggs) or by definition (e.g., 1 inch = 2.54 cm).
Numbers in scientific notation: All digits in the mantissa (the part before "x 10^") are significant.
Example: 1.23 x 10^4 has 3 significant figures.
Example: 5.00 x 10^-2 has 3 significant figures.
Examples of Counting Significant Figures:
45.8735: 6 significant figures (all non-zero)
0.000239: 3 significant figures (leading zeros are not significant)
500.: 3 significant figures (trailing zeros are significant because of the decimal point)
500: 1 significant figure (trailing zeros are not significant without a decimal point)
1002.0: 5 significant figures (zeros between non-zeros are significant, and trailing zero after decimal is significant)
3.0 x 10^5: 2 significant figures (from the mantissa 3.0)
Using the calculator above can help you practice and verify your understanding of these rules for various numbers.