Significant figures (often called "sig figs") are the digits in a number that carry meaningful information about its precision. In scientific measurements, the number of sig figs tells the reader how accurate the measurement is, indicating which digits are certain and which one is the final estimated digit.
The 4 Golden Rules of Significant Figures:
Non-zero digits: All non-zero numbers (1-9) are always significant.
Sandwiched zeros: Zeros between non-zero digits are always significant (e.g., 405 has 3 sig figs).
Leading zeros: Zeros to the left of the first non-zero digit are never significant (e.g., 0.002 has only 1 sig fig).
Trailing zeros: Zeros at the end of a number are significant only if there is a decimal point (e.g., 150.0 has 4 sig figs, but 150 typically has 2).
Why Precision Matters
In chemistry, physics, and engineering, you cannot report a result that is more precise than your least precise measurement. For example, if you measure a table with a ruler that only shows centimeters, you cannot claim the table is exactly 120.4532 millimeters long. The sig figs calculator helps you maintain scientific integrity by rounding your calculations to the appropriate level of uncertainty.
400.0: 4 Significant Figures (trailing zeros after decimal are significant).
1,020: 3 Significant Figures (trailing zero without decimal is usually not significant).
6.022 x 1023: 4 Significant Figures (only the coefficient is counted).
function processSignificantFigures() {
var inputVal = document.getElementById('numberInput').value.trim();
var roundTo = document.getElementById('roundTo').value;
var resultsPanel = document.getElementById('resultsPanel');
if (inputVal === "" || isNaN(parseFloat(inputVal))) {
alert("Please enter a valid numeric value.");
return;
}
var count = countSigFigs(inputVal);
document.getElementById('sigCountDisplay').innerText = count;
var numObj = parseFloat(inputVal);
document.getElementById('scientificDisplay').innerText = numObj.toExponential();
if (roundTo !== "" && parseInt(roundTo) > 0) {
var target = parseInt(roundTo);
var rounded = numObj.toPrecision(target);
document.getElementById('roundedValueDisplay').innerText = rounded;
document.getElementById('roundedRow').style.display = 'flex';
} else {
document.getElementById('roundedRow').style.display = 'none';
}
resultsPanel.style.display = 'block';
}
function countSigFigs(n) {
var s = n.toString().toLowerCase().trim();
// Handle scientific notation e.g. 6.02e23
if (s.indexOf('e') !== -1) {
s = s.split('e')[0];
}
// Remove negative sign
s = s.replace(/^-/, ");
// If it's just zero
if (parseFloat(s) === 0) {
// "0.00" has significance if decimal is present and trailing
if (s.indexOf('.') !== -1) {
// Remove leading zeros: 0.00 -> .00 -> length 2 (incorrect, logic below is better)
var decimalParts = s.split('.');
if(parseInt(decimalParts[0]) === 0) {
// It's like 0.000 -> count trailing zeros
return s.length – s.indexOf('.') – 1;
}
}
return 1;
}
if (s.indexOf('.') !== -1) {
// Rule: With decimal, count from first non-zero to the end
// 0.00120 -> 120 (3)
s = s.replace('.', ");
var firstNonZero = -1;
for (var i = 0; i 12 (2)
var clean = s.replace(/^0+/, "); // Leading zeros
clean = clean.replace(/0+$/, "); // Trailing zeros (ambiguous rule – standard is non-sig)
return clean.length;
}
}