Growth/BMI results: percentiles to 2 decimal places

Percentile displays in growth charts, BMI, and mid-parental height
now show 2 dp (e.g. "37.42th") instead of 1 dp ("37.4th") for more
precision at tail percentiles.
This commit is contained in:
Daniel 2026-04-14 03:37:40 +02:00
parent 45244d4eeb
commit a8a3ade069

View file

@ -736,7 +736,7 @@
}
// Convert Z to percentile using standard normal CDF approximation
var p = normalCDF(z);
return { z: z, percentile: Math.round(p * 1000) / 10 };
return { z: z, percentile: Math.round(p * 10000) / 100 };
}
function normalCDF(z) {
@ -1115,7 +1115,7 @@
}
function renderGrowthResult(label, value, unit, z, percentile) {
var pctl = Math.round(percentile * 10) / 10;
var pctl = (Math.round(percentile * 100) / 100).toFixed(2);
var cl;
if (pctl >= 95 || pctl <= 5) cl = { color: '#f59e0b', bg: '#fef3c7', text: pctl <= 5 ? 'Below 5th percentile' : 'Above 95th percentile' };
else if (pctl >= 85 || pctl <= 15) cl = { color: '#f97316', bg: '#ffedd5', text: pctl + 'th percentile' };
@ -1207,7 +1207,7 @@
// Calculate what percentile the MPH corresponds to using adult height LMS (~18y = 216mo)
var adultLms = interpolateLMS(cdcLfaLMS[sex], 216);
var mphZ = calcZFromLMS(mph.target, adultLms.L, adultLms.M, adultLms.S);
var mphPctile = Math.round(normalCDF(mphZ) * 1000) / 10;
var mphPctile = (Math.round(normalCDF(mphZ) * 10000) / 100).toFixed(2);
resultDiv.innerHTML += '<div style="margin-top:8px;padding:8px 12px;background:#ede9fe;border-radius:6px;font-size:13px;color:#6d28d9;"><strong>Mid-Parental Height:</strong> ' + mph.target.toFixed(1) + ' cm (' + mphPctile + 'th percentile) &mdash; target range: ' + mph.low.toFixed(1) + ' - ' + mph.high.toFixed(1) + ' cm</div>';
// MPH coordinates: use years if age > 24mo
var mphX1 = age > 24 ? 17 : 204;