How I Stepped on This Ledger
A while back I took a made-up dataset to the weighted average page and started reconciling it. Two value rows, 90 and 80. I entered the weights first as percentages, 30/70, and the headline came back as 83. I switched to the fraction form, 3/7, and it was still 83. I switched again to the coefficient form, 0.3/0.7, and it was 83 once more. Only the weight total in the stats bar moved, stepping through 100, then 10, then 1. What tied my attention to the on-page hint text was the per-item contribution table: the page states that all contributions added together equal the weighted average, so I added the displayed contributions as shown, and they summed to 0.9999. Later I separated normalization, rounding order and the error paths and checked each on its own.
Normalization: Three Weight Notations in One Table
Reading waCalc once confirms the behaviour: the headline comes from the sum of value times weight divided by the sum of weights, an unconditional division with no branch that says only normalize once the weights reach 100. That is why the three notations produce identical per-item output while the values stay 90/80, and why only the presentation layer changes. Every figure below comes from loading the template script block verbatim into Node and calling the page's own function, with no browser opened.
| Value input | Weight input | Weighted average | Weight total | Contribution column |
|---|---|---|---|---|
| 90 / 80 | 30 / 70 | 83 | 100 | 27, 56 |
| 90 / 80 | 3 / 7 | 83 | 10 | 27, 56 |
| 90 / 80 | 0.3 / 0.7 | 83 | 1 | 27, 56 |
| 90 / 80 | 1 / 2 | 83.3333 | 3 | 30, 53.3333 |
The last row is a sample built so that the weight sum is not 100: weights 1 and 2, and the page simply divides by 3, with the process line written out as ((90x1) + (80x2)) / 3 = 83.3333. The share column is pinned to two decimals, so the 30/70 group shows 30.00% and 70.00%, while the 1/2 group shows 33.33% and 66.67%. The hint saying you never have to reach 100% is genuine: write the weights however you like, the page divides them back.
Figure 1: the divisor is the weight sum each notation accumulates, all three converge on one headline, and only the stats bar moves.
The Contribution Column Rounding Ledger: Round Each Row First, Then Show and Add
Reconciliation forks at the contribution table, because this page carries two rounding orders. Each contribution cell is rounded on its own first, row by row, through Math.round(value times share times 10000)/10000 down to 4 places, and only then placed on screen; the headline, by contrast, is summed as a whole and rounded once at the end. Integer samples hide the difference, so build a division that never terminates.
- Values 1/1/1, weights 1/1/1: each contribution displays 0.3333, the column sums to 0.9999, which is 0.0001 short of the headline value 1.
- Values 2/2/2, weights 1/1/1: each contribution displays 0.6667, the column sums to 2.0001, and now it is 0.0001 too much.
- Values 0.1/0.2, weights 1/2: contributions 0.0333 plus 0.1333 give 0.1666, while the headline on the same screen reads 0.1667.
- Values 10/20/33, weights 1/1/1: 3.3333, 6.6667 and 11 add up to exactly the headline value 21, so this group shows no gap.
Whether the ledger balances has nothing to do with the presence of decimals; it depends on whether the fifth place of each row rounds in or rounds out. Headline rounding is half-up rather than truncation, and trailing zeros are stripped, so an integer contribution displays as 11 rather than 11.0000, and the pair 90 with weight 1e3 gives a headline of 89.99 against a weight total of 1001. The sentence claiming that all contributions added together equal the weighted average therefore does not hold in the decimal tier, and reusing the column as a second check means reserving a tolerance of plus or minus 0.0001 or reading the process line instead.
Figure 2: three equal weight samples, one short by 0.0001, one over by 0.0001, one that lands dead level.
The Process Line Does Not Lie: Raw Floating Point Values Reach the Screen
The calculation process card is assembled from the unrounded floating point accumulator, which makes it the most honest line on the page. Enter weights 0.1 and 0.2 and the weight sum accumulates in double precision as 0.30000000000000004, and the process line prints it as computed, as ((90x0.1) + (80x0.2)) / 0.30000000000000004 = 83.3333. At that same instant the weight total in the stats bar has passed through Math.round(x10000)/10000 and hands you a tidy 0.3. One accumulated sum, two sets of books on one screen. Enter 1e21 as a value and multiplying by 10000 pushes the product past the exact integer limit at 2^53; dividing back leaves the headline as 1.0000000000000001e+21, and that spurious tail comes from the rounding step. The highest and lowest readings in the same stats bar skip that step and show 1e+21 directly.
Errors Are a Notice, Not a Gate
Errors here are not a hard block. Put one invalid value, abc, in a row and keep the other row as the usual 90 with weight 1: the error box reports a value that is not a valid number, while the results area still publishes its figures, headline 90, process line ((90x1)) / 1 = 90, the invalid row silently removed from the ledger. Negative weights behave the same: the page reports that weights must be non-negative numbers, and the legal rows still yield a headline. Only one condition removes the results area, the message that the weight total is zero and a weighted average cannot be computed because the weights cannot all be zero. Leaving a field blank is not entering zero: a blank weight is treated as 1, so three rows of 90/80/70 with every weight blank give a headline of 80, agreeing with the plain arithmetic mean the stats bar reports. A value written as 90abc raises no complaint either, because the parser truncates at the first non numeric character and a leading 90 enters the calculation. Both findings came from measuring at the code layer by bypassing the input boxes; both boxes are type=number controls, and whether a real browser accepts such a token was not measured in this pure Node pass.
Bulk Rows, Clearing, and Row Numbers
Two entries on the bulk side. A 20 row sample where every value is 80 and every weight is 5 returns a headline of 80, each row share reads 5.00%, each contribution is 4, and the column sums to exactly 80, so this tier carries no gap. Recomputing identical input twice produces character for character identical output, with no accumulator carried over. Clear everything and initialize again and the table body is rebuilt to the default rows of first paint, but row identifiers continue upward from wa-row-4 and the counter only increases. The comment shipped with those default rows does not match what the code supplies, so reconciliation follows the measurement.
Cross References
The page measured here is the weighted average calculator itself; the general rules for displayed digits and trailing zeros live in the decimal format article, and the round(x10000)/10000 used on this page is that scheme landing on one tool; the ledger about asymmetric ratio baselines is measured again in the percentage baseline note, and this article keeps only this page's numbers.
Q: Do the Weights Have to Add Up to 100?
They do not, because the page always divides by the weight sum. On values 90/80 the notations 30/70, 3/7 and 0.3/0.7 all give a headline of 83 and contributions of 27 and 56, and a weight pair of 1/2, whose sum is only 3, is normalized the same way and lands on 83.3333.
Q: Is the Column Wrong When It Cannot Reproduce the Headline?
It is not a computation error but two rounding orders, since each contribution row is rounded to 4 places on its own first while the headline is summed and rounded afterwards. The 1/1/1 group is 0.0001 short, the 2/2/2 group is 0.0001 over in the opposite direction, and the 10/20/33 group balances exactly. For a precise check, follow the raw expression in the process line.
Q: Can the Results Still Be Trusted Beside an Error?
When the notice and the results share the screen, the results only count legal rows, and an invalid row enters neither the numerator nor the denominator; only the tier where every weight is zero takes the results area away.