Where the two standard-deviation outputs fork
The first time I seriously cross-checked the two outputs on this page was over a set of eight exam scores: 88 92 95 79 84 90 91 85. The main value cell returned 5.12696, while the first row of the comparison table read 4.795832, and dividing one by the other gives 1.069045. My first reaction was that the page ran two separate algorithms. Later I loaded the script block verbatim into Node and reproduced it line by line, and only then did the account add up: the two conventions share one and the same sum-of-squares loop and only fork at the divisor step, n versus n−1; they are not two independent computations. The ratio itself equals √(8/7), and the remaining difference sits entirely in display-layer rounding.
The script block is 4563 B, 104 lines, 5 functions; every keystroke triggers a full recalculation, there is no accumulated state and no network call, and all computation stays local. Every number below comes from reruns of the standard deviation calculator page itself, with no browser opened.
One sum of squares, two divisors
The code path is short: one loop folds out the mean, then a separate loop accumulates the squared distance of each value from the mean; with that single sum of squares in hand, the population convention divides by n and the sample convention divides by n−1, so both variances feed on the same ss. Checking against the eight numbers prefilled by the fill-example-data button: n = 8, mean x̄ = 88, sum of squares Σ(x−x̄)² = 184, and the two conventions differ only in the last division.
| Convention | Divisor written | Variance shown | Std deviation shown |
|---|---|---|---|
| Population (÷ n) | 184 ÷ 8 | 23 | 4.795832 |
| Sample (÷ n−1) | 184 ÷ 7 | 26.285714 | 5.12696 |
The comparison table always lists the population row first and the sample row second; the 40px main value cell takes the sample convention, and the sub-line reads n = 8, mean x̄ = 88. The first segment of the formula line is the easiest to misread: the dividend in the mean step is the grand total, which expands to 704 ÷ 8 = 88; when n falls below 2 the sample-variance segment is omitted outright rather than a 0 placeholder.
1.069045 and √(8/7): the whole gap lives in 6-digit rounding
The ratio account needs a set whose variance comes out rounder: input 2 4 4 4 5 5 7 9, sum of squares 32, population variance 32 ÷ 8 = 4, so σ lands on the exact integer 2, and the sample standard deviation s displays 2.13809; the display-layer ratio is 2.13809 ÷ 2 = 1.069045. The theoretical value √(8/7) = 1.069044967…, and the measured difference is 3.235e-8. That 3.235e-8 does not mean anyone miscalculated — it is what you get when sdRound cuts both numbers to 6 decimal places first and the two truncated displays are then divided. There is no ratio correction term anywhere in the code; the entire shortfall comes from rounding.
The one rounding device for the whole page is sdRound(x, n) = Math.round(x*10^n)/10^n: every displayed quantity passes through it, at a uniform 6 decimal places, and it belongs to the Math.round family rather than toFixed. The true value 2.13808993 shows as 2.13809, and the trailing zero simply disappears; feed in 0.1 0.2 0.3000004 and the true range 0.2000004 is rounded down into 0.2, while the max and min cells skip rounding altogether.
Paste splitting: full-width separators weigh the same, one bad segment rejects the batch
The splitting is handed to a single regex whose character class takes half-width and full-width separators alike. Chinese commas in 1,2,3 still form a group of n = 3; the enumeration commas in 1、2、3 likewise give n = 3; the Chinese semicolon in 4;5 yields n = 2; full-width spaces are caught by the whitespace class too, so 1 2 feeds in two numbers as well. Empty segments carved out by repeated separators do not take up a slot in the count: ",,1;;2,,3,," is still n = 3.
Number() silently changes its face on literal forms such as hexadecimal, scientific notation and trailing-dot decimals: 0x10 enters the group as 16 and is computed together with 5, giving a main value of 7.778175; 1e3 folds into 1000; 3. folds into 3 without a word. A genuinely broken segment, however, rejects the whole batch instead of being skipped one by one: 1 abc 2, 1 NaN 2 and 1 Infinity all report that an unrecognized numeric fragment exists, asking you to check the separators and the content, and the result area is hidden entirely. The grand ledger over 18 groups of input: 13 groups produce numbers normally, 3 groups fail in batch, 2 groups fall into the empty state.
n = 1, n = 0 and all-identical values: each boundary takes its own road
Enter the single number 42: both the main value cell and the variance and std-deviation cells of the sample row show dashes, and the sub-line swaps its whole sentence for a dedicated notice that with n = 1 the sample standard deviation cannot be computed and at least 2 values are required; the population row still hands out 0 as usual, the statistics strip still renders in full, and the formula line only runs as far as the population segment: 42 ÷ 1 = 42; Σ = 0; 0 ÷ 1 = 0. A purely blank input walks a different road: it is intercepted by trim before any splitting, reports no error, and shows the empty-state hint that pasting data triggers the calculation automatically with no button to press — the empty state and the error state are mutually exclusive. The all-identical group 5 5 5 5 comes out 0 under both conventions at once, neither an error nor a dash; two extreme values -1000000 1000000 remain perfectly computable at n = 2, with a main value of 1414213.562373.
For an even count of values the median takes the average of the two middle numbers after sorting: 1 2 4 7 gives (2 + 4) ÷ 2 = 3; switch to 2 4 4 4 5 5 7 9 and you get (4 + 5) ÷ 2 = 4.5. The sort runs a numeric pass with a subtraction comparator, not a lexicographic one.
Large numbers switch display form past 1e21
The display string is simply the Number converted to a string, with no formatting at all. Input 1e15 2e15 3e15: the population standard deviation shows as 816496580927726, one unbroken run of full digits; yet the sum of squares of the same set displays as 2e+30 and the population variance as 6.666666666666666e+29 — the threshold sits at 1e21, and only values reaching it convert into e notation. Look at 1e21 2e21 next: the mean 1.5e+21 has entered notation, while the sample standard deviation 707106781186547500000 is still written out in full digits. Two display forms side by side on one screen simply record whether each quantity's magnitude crossed the 1e21 line. For the same family of digit-count and rounding questions, the decimal formatting tool page works at them from another direction, and the older note on decimal places and rounding modes keeps an even finer account of the 6-decimal rule and its trailing zeros.
Three common questions
Q: Why is the main value 5.12696 rather than 4.795832?
The main slot carries the sample convention and the first row of the comparison table carries the population one; both numbers come from the same 184 and differ only by whether the divisor is 7 or 8. The page's own wording says: when the question asks for the standard deviation of this data set, use the population convention; when it says sample standard deviation, or the data is a sample, use the sample convention. Copy the page text as-is; do not settle the question for anyone.
Q: Why is the ratio of the two values not exactly √(8/7)?
Both numbers that enter the division are display values after sdRound to 6 places: 2.13809 divided by 2 gives 1.069045, which differs from 1.069044967… by 3.235e-8; and that 3.235e-8 is a rounding account, not a formula account.
Q: Will one stray Chinese character void the whole paste?
It will: if any single segment fails to convert into a finite number, the whole batch returns empty and the error shows — the bad segment is never dropped on its own. But literal forms that Number() recognizes, like 0x10, 1e3 and 3., fold silently into the group, and that part is exactly what deserves a glance before you paste.
Two closing strokes
How to reproduce: the script block is self-contained, so loading it whole into node:vm with a minimal DOM stub runs everything; no browser was opened for this set of numbers, and anything unreachable is labeled unmeasured. An older article on arithmetic sequences mentioned variance and summation figures in passing; this one quotes none of them — every variance, standard deviation and ratio here comes from measured cross-checks over this page's own inputs.