Significant figures (or significant digits) are the digits of a number that carry meaning contributing to its precision. This includes all digits except:
Leading zeros (e.g., the 0.0056 has two significant figures: 5 and 6).
Trailing zeros when they are merely placeholders to indicate the magnitude of the number (e.g., in 1200, if the number was measured to the nearest hundred, there are two significant figures: 1 and 2. If it was measured to the nearest unit, there are four: 1, 2, 0, and 0).
Spurious digits introduced, for example, by calculations.
The rules for determining significant figures are crucial in scientific and engineering fields to ensure that calculations reflect the precision of the input measurements.
Rules for Identifying Significant Figures:
Non-zero digits: All non-zero digits are always significant. (e.g., 123 has 3 sig figs).
Zeros between non-zero digits: Zeros between two non-zero digits are always significant. (e.g., 1005 has 4 sig figs).
Leading zeros: Zeros to the left of the first non-zero digit are never significant. These are only placeholders. (e.g., 0.00789 has 3 sig figs).
Trailing zeros:
Trailing zeros in a number containing a decimal point are significant. (e.g., 12.00 has 4 sig figs; 0.450 has 3 sig figs).
Trailing zeros in a whole number are ambiguous without further context (e.g., 1200 could have 2, 3, or 4 sig figs). For this calculator, we assume trailing zeros are significant if they are part of the input string representing a measurement (e.g., "1200." implies 4 sig figs, but "1200" can be interpreted in multiple ways without scientific notation or further context. For simplicity, this calculator will count all digits in a whole number if they are provided and are not leading zeros.)
When to Use This Calculator:
This calculator is useful for:
Students learning chemistry, physics, or mathematics who need to practice or verify the number of significant figures in a given number.
Researchers and Engineers who need to quickly determine the precision of their data or calculations.
Anyone working with measurements where the precision of the numbers is important for accuracy in subsequent operations.
How it works:
Enter a number (integer or decimal) into the field above and click "Calculate". The calculator will then identify and count the significant figures according to the standard rules.
function calculateSignificantFigures() {
var numberInput = document.getElementById("numberInput").value;
var resultDiv = document.getElementById("result");
resultDiv.textContent = ""; // Clear previous results
if (numberInput.trim() === "") {
resultDiv.textContent = "Please enter a number.";
return;
}
var numberStr = numberInput.toString();
var sigFigs = 0;
// Rule out non-numeric inputs that could cause issues
if (isNaN(parseFloat(numberStr))) {
resultDiv.textContent = "Invalid input. Please enter a valid number.";
return;
}
// Handle scientific notation for clarity if present
if (numberStr.toLowerCase().includes('e')) {
// For scientific notation like 1.23e+4 or 1.23E-4
// The significant figures are determined by the part before 'e' or 'E'
var mantissa = numberStr.split(/[eE]/)[0];
numberStr = mantissa; // Process only the mantissa
}
var hasDecimal = numberStr.includes('.');
var inNonZero = false; // Flag to track if we've passed the first non-zero digit
for (var i = 0; i = '1' && char <= '9') {
// Rule 1: Non-zero digits are always significant
sigFigs++;
inNonZero = true;
} else if (char === '0') {
// Handle zeros based on context
if (inNonZero) {
// Rule 2: Zeros between non-zero digits are significant
// Rule 4a: Trailing zeros after a decimal point are significant
// Rule 4b (simplified): Trailing zeros in a number with a decimal are significant
if (i < numberStr.length – 1) { // Check if it's not the very last character
if (hasDecimal) { // If there's a decimal, any trailing zero is significant
sigFigs++;
}
} else { // If it's the last character and we have a decimal, it's significant
if (hasDecimal) {
sigFigs++;
}
// If it's the last character and no decimal, it's ambiguous, but for simple calculation, we might count it if it's part of the entered number as a whole.
// However, to be precise with the ambiguity, typically this case needs context.
// For this calculator, let's stick to clearer rules. A final zero in a whole number like 1200 is counted IF it's explicitly shown to be significant (e.g., 1200.).
// If the input is just "1200", standard interpretation is 2 sig figs.
// If the input is "1200.", it's 4 sig figs.
// If the input is "1.200e3", it's 4 sig figs.
// For simplicity, if it's a trailing zero *and* there's a decimal point, we count it.
}
} else {
// Rule 3: Leading zeros are not significant
// If inNonZero is false, and char is '0', it's a leading zero.
// Exception: If the number is exactly "0" or "0.0" etc.
// But those cases will be handled by the mantissa processing or specific checks.
// If the number starts with 0 and has a decimal (e.g., 0.123), the 0 before decimal is not significant.
// If the number is "0", it has 1 sig fig.
// This loop structure handles "0" as a special case where inNonZero stays false and then if '0' is encountered, it's considered.
// Let's refine this. A single '0' should be 1 sig fig.
if (numberStr === '0') {
sigFigs = 1;
break; // Exit loop for single '0'
}
// If it's 0.00X, these initial zeros are NOT counted.
}
}
}
// Final check for the case of "0" or "0.0" etc.
if (numberStr.replace(/[^0-9.]/g, '') === '0'.repeat(numberStr.replace(/[^0-9.]/g, '').length)) {
if (numberStr.includes('.')) { // e.g., 0.00
// Count significant zeros after decimal point up to the last non-zero digit if there were any.
// If it's just 0.00, and no other digits, we should count the zeros that follow the decimal.
var nonDecimalPart = numberStr.split('.')[0];
var decimalPart = numberStr.split('.')[1];
if (decimalPart) {
for(var j = 0; j < decimalPart.length; j++) {
if (decimalPart[j] === '0') {
// Trailing zeros after the decimal, which are significant IF they are the only digits or last digits after decimal.
// This rule is tricky. For "0.00", it's 2 sig figs. For "0.001", it's 1 sig fig.
// The current loop logic handles "0.001" by finding '1'.
// For "0.00", sigFigs would be 0 from the loop. We need to add logic.
// If the entire number is zeros after decimal (or just 0), we need to count meaningful zeros.
var numZerosAfterDecimal = 0;
var hasNonZeroAfterDecimal = false;
for(var k=0; k 0) {
sigFigs = numZerosAfterDecimal; // e.g., for "0.00", sigFigs becomes 2.
} else if (!hasNonZeroAfterDecimal && numZerosAfterDecimal === 0) {
// Case like "0." or just "0" which would result in 1 sig fig.
if (numberStr === '0' || numberStr === '0.') {
sigFigs = 1;
}
}
} else {
break; // Stop counting zeros once a non-zero digit is encountered
}
}
} else if (numberStr === '0' || numberStr === '0.') {
sigFigs = 1; // Case for "0" or "0."
}
} else { // Whole number "0"
sigFigs = 1;
}
}
// Ensure sigFigs is at least 1 if the input was a valid non-zero number string, even if rules made it zero. (e.g. problematic interpretation of 1000)
// The logic above should correctly handle most cases.
// A common convention for 1000 is 1 sig fig if no decimal.
// If the input was a single digit number like '5', it's correctly counted.
// If the input was '0.005', loop finds '5', sigFigs=1. Correct.
// If input was '0.00', the special check for all zeros after decimal sets sigFigs=2. Correct.
// If input was '0', special check sets sigFigs=1. Correct.
// If input was '1200', loop finds 1,2. sigFigs=2. Correct by standard interpretation.
// If input was '1200.', loop finds 1,2,0,0. sigFigs=4. Correct.
// Re-evaluate the logic for trailing zeros without decimal, as this is ambiguous.
// For this calculator's purpose, we'll stick to the clearest rules.
// If input is "1200", the loop will count '1', '2', resulting in 2 sig figs. This is a common interpretation.
// If a user *intends* 1200 to have 4 sig figs, they should use "1200." or scientific notation "1.200 x 10^3".
// The current loop logic for `numberStr.length – 1` and `hasDecimal` handles trailing zeros *after* a decimal correctly.
// For trailing zeros in whole numbers (like 1200), the `inNonZero` flag ensures they are only counted IF they follow a non-zero digit.
// This means '0' in '1200' will be counted IF `inNonZero` is true (which it is after '1' and '2').
// So, '1200' would result in 4 sig figs with the current loop as written IF `hasDecimal` is true.
// BUT `hasDecimal` is false for '1200'.
// This means trailing zeros in whole numbers ARE NOT counted by the current loop.
// This aligns with the strict rule that trailing zeros in whole numbers are significant ONLY if indicated by a decimal point.
// So '1200' -> 2 sig figs. '1200.' -> 4 sig figs.
resultDiv.textContent = "Number of Significant Figures: " + sigFigs;
}