Short Answer
Rule Statement
Significant figures (sig figs) are the digits in a number that carry meaning contributing to its measurement resolution. The rules for determining sig figs are well established: all non-zero digits are significant; zeros between non-zero digits are significant; leading zeros are not significant; trailing zeros are significant only if the number contains a decimal point. When rounding to a given number of sig figs, the standard convention (as per ASTM E29 and ISO 80000) is to round half away from zero, unless otherwise specified. However, programming languages and database systems often implement different rounding modes, leading to discrepancies that can affect scientific and engineering calculations.
This article compares the default rounding behaviour of R, MATLAB, JavaScript, and SQL, highlighting where they align with or deviate from the standards. It also provides practical guidance for achieving consistent sig-fig handling across these environments.
Software Behavior Note
R
R’s round() function uses banker’s rounding (round half to even) by default. For example, round(2.5) returns 2, and round(3.5) returns 4. This is consistent with the IEEE 754 standard for floating-point arithmetic, but it differs from the common “round half up” taught in many classrooms. To round half away from zero, use round(x, digits = 0, ...) with the round5 argument in newer versions, or use zapsmall() for display purposes. For sig figs, R’s signif() function rounds to a specified number of significant digits, but it also uses banker’s rounding for ties.
MATLAB
MATLAB’s round() function rounds half away from zero. For example, round(2.5) returns 3, and round(-2.5) returns -3. This matches the ASTM E29 default. MATLAB also provides round(X, N) for rounding to N decimal places, and round(X, N, 'significant') for rounding to N significant digits. The latter uses the same half-away-from-zero rule.
JavaScript
JavaScript’s Math.round() rounds half up (towards positive infinity) for positive numbers, but for negative numbers it rounds half towards positive infinity as well (e.g., Math.round(-2.5) returns -2, not -3). This is asymmetric and can introduce bias in data processing. For sig figs, JavaScript lacks a built-in signif() function; developers must implement custom logic using toPrecision() or toExponential(), which use round half up (towards positive infinity) for all numbers.
SQL
SQL behaviour varies by database system. MySQL’s ROUND() rounds half away from zero. PostgreSQL’s ROUND() for numeric types also rounds half away from zero, but for double precision it uses round half to even (banker’s rounding). SQL Server’s ROUND() uses round half away from zero by default, but offers a third parameter to control truncation. Oracle’s ROUND() rounds half up. There is no standard SQL function for significant digits; you must use ROUND(value, -n) with negative decimal places to round to tens, hundreds, etc., but this only works for powers of ten, not arbitrary sig figs.
Worked Examples
Example 1: Rounding 0.0004567 to 2 sig figs
In R: signif(0.0004567, 2) returns 0.00046 (since the first two significant digits are 4 and 5, and the next digit 6 rounds up). In MATLAB: round(0.0004567, 2, 'significant') returns 0.00046. In JavaScript: Number(0.0004567.toPrecision(2)) returns 0.00046. In SQL (MySQL): ROUND(0.0004567, 2) would round to 2 decimal places, not 2 sig figs; you need ROUND(0.0004567, -2)? Actually that rounds to hundreds. For sig figs, you’d need to use scientific notation: ROUND(0.0004567 * 1000, 0) / 1000? That’s messy. The correct approach is to use ROUND(0.0004567, 2 - FLOOR(LOG10(0.0004567)) - 1) but that’s complex. We’ll note that SQL lacks a direct sig-fig function.
Example 2: Rounding 2.5 to 1 sig fig
R: signif(2.5, 1) returns 2 (banker’s rounding). MATLAB: round(2.5, 1, 'significant') returns 3 (half away from zero). JavaScript: Number(2.5.toPrecision(1)) returns 3 (half up). SQL (MySQL): ROUND(2.5, 0) returns 3 (half away from zero). This example highlights the critical difference in tie handling.
Counter-Examples
Counter-example 1: Using round() in R for scientific data — A chemist measures a mass of 2.5 g and needs to report it to 1 sig fig. Using R’s default round(2.5, 0) yields 2, which under-reports the measurement. The correct value per ASTM E29 is 3. This can lead to significant errors in subsequent calculations.
Counter-example 2: JavaScript’s asymmetric rounding — In a financial application, summing values like -2.5 and 2.5 using Math.round() gives -2 and 3, respectively, introducing a bias of +0.5. This violates the principle of unbiased rounding required by many standards.
Counter-example 3: SQL’s inconsistent behaviour across DBMS — A data pipeline that moves from MySQL to PostgreSQL may produce different results for the same query, because PostgreSQL’s double precision uses banker’s rounding while MySQL uses half away from zero. This can break reproducibility in scientific databases.
Convention Comparison Table
| Language/System | Default Rounding Mode | Sig Fig Function | Tie Handling | Standards Alignment |
|---|---|---|---|---|
| R | Banker’s rounding | signif() |
Round half to even | IEEE 754, not ASTM E29 |
| MATLAB | Half away from zero | round(...,'significant') |
Round half away from zero | ASTM E29, ISO 80000 |
| JavaScript | Half up (towards +∞) | toPrecision() |
Round half up | Not aligned with common standards |
| SQL (MySQL) | Half away from zero | None (manual) | Round half away from zero | ASTM E29 |
| SQL (PostgreSQL) | Numeric: half away; double: banker’s | None (manual) | Varies by type | Inconsistent |
Standards Citation
ASTM E29-22, “Standard Practice for Using Significant Digits in Test Data to Determine Conformance with Specifications,” specifies that when rounding to a given number of significant digits, the “round half away from zero” rule shall be used unless otherwise stated (Section 6.1.2). ISO 80000-1:2022, “Quantities and units – Part 1: General,” recommends rounding to the nearest value with ties rounded to the nearest even digit (Section 7.4) for statistical purposes, but allows other conventions when clearly stated. NIST Technical Note 1297, “Guidelines for Evaluating and Expressing the Uncertainty of NIST Measurement Results,” advises that rounding of measurement results should be consistent with the uncertainty, and that the number of significant figures should reflect the uncertainty (Section 7.2). The GUM (JCGM 100:2008) similarly emphasizes that reported results should not have more digits than justified by the uncertainty (Clause 7.2.6).
In practice, for engineering and scientific reporting, ASTM E29 is the most commonly cited standard for rounding to significant figures. Therefore, MATLAB’s default behaviour aligns well, while R and JavaScript require explicit adjustment to meet this standard.
Common Mistakes
- Assuming all languages round half up — As shown, R uses banker’s rounding, and JavaScript uses half up for positive but half towards positive infinity for negative numbers.
- Using
round()for sig figs instead of a dedicated function — In R,round(x, digits)rounds to decimal places, not significant digits. Usesignif(). - Ignoring floating-point representation — In JavaScript,
0.1 + 0.2is not exactly 0.3, so rounding to sig figs can produce unexpected results. Always usetoPrecision()on the result. - Applying SQL
ROUND()with negative digits for sig figs —ROUND(1234, -2)rounds to hundreds, not to 2 sig figs. For 2 sig figs, you need to round to the nearest 10, which isROUND(1234, -1)— but this only works for certain magnitudes. - Not considering the uncertainty — Sig figs are meaningless without an associated uncertainty. Always report the uncertainty and round the measurement to match its magnitude.
Quick Reference Table
| Task | R | MATLAB | JavaScript | SQL (MySQL) |
|---|---|---|---|---|
| Round to 3 decimal places | round(x, 3) |
round(x, 3) |
Number(x.toFixed(3)) |
ROUND(x, 3) |
| Round to 3 sig figs | signif(x, 3) |
round(x, 3, 'significant') |
Number(x.toPrecision(3)) |
Manual: ROUND(x, 2 - FLOOR(LOG10(x))) |
| Round half away from zero | round(x, 0, round5 = TRUE) (R ≥ 4.0) |
round(x) |
Custom function | ROUND(x, 0) |
| Round half to even | round(x) |
Not default | Not default | PostgreSQL double: ROUND(x::double precision) |
Sources & Further Reading
- ASTM E29-22, “Standard Practice for Using Significant Digits in Test Data to Determine Conformance with Specifications,” ASTM International, 2022.
- ISO 80000-1:2022, “Quantities and units – Part 1: General,” ISO, 2022.
- NIST Technical Note 1297, “Guidelines for Evaluating and Expressing the Uncertainty of NIST Measurement Results,” 1994.
- JCGM 100:2008, “Evaluation of measurement data — Guide to the expression of uncertainty in measurement (GUM),” BIPM, 2008.
- R Core Team, “R: A Language and Environment for Statistical Computing,” R Foundation, 2024. R documentation
For more on rounding methods, see our Rounding Methods guide. For a deeper dive into significant figure rules, visit Significant Figures Rules.
FAQ
What are significant figures and why are they important?
Significant figures represent digits in a number that contribute to its precision, helping to convey measurement resolution and uncertainty accurately.
How do R, MATLAB, JavaScript, and SQL differ in rounding?
R uses banker's rounding, MATLAB rounds half away from zero, JavaScript uses half up for positives but rounds half towards positive infinity for negatives, and SQL's rounding varies by database system.
Does SQL have a built-in function for rounding to significant figures?
No, SQL lacks a dedicated function for rounding to significant figures, requiring complex manual calculations or approximations.
Which rounding method aligns best with ASTM E29?
MATLAB's half away from zero rounding aligns best with ASTM E29 standards.
What are common pitfalls in programming sig fig rounding?
Common pitfalls include using decimal rounding functions instead of sig fig functions, ignoring floating-point quirks, inconsistent rounding modes across languages, and neglecting uncertainty considerations.

Leave a Reply