From a8a3ade06929504bd8e8bf8232c63bcbe4e0b668 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 14 Apr 2026 03:37:40 +0200 Subject: [PATCH] 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. --- public/js/calculators.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/js/calculators.js b/public/js/calculators.js index 64e839d..133b4d7 100644 --- a/public/js/calculators.js +++ b/public/js/calculators.js @@ -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 += '
Mid-Parental Height: ' + mph.target.toFixed(1) + ' cm (' + mphPctile + 'th percentile) — target range: ' + mph.low.toFixed(1) + ' - ' + mph.high.toFixed(1) + ' cm
'; // MPH coordinates: use years if age > 24mo var mphX1 = age > 24 ? 17 : 204;