From 64d4f68eb3a6dd45ec8f5bb65a1efe5f23a9fdbc Mon Sep 17 00:00:00 2001 From: dm5wk Date: Mon, 3 Jun 2024 21:48:54 +0200 Subject: [PATCH] add digits after comma for showing e. g. 145.500 MHz --- band-plan-iaru_r1_hf.yml | 1 + band-plan.html | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/band-plan-iaru_r1_hf.yml b/band-plan-iaru_r1_hf.yml index f4f6c72..54e6b1f 100644 --- a/band-plan-iaru_r1_hf.yml +++ b/band-plan-iaru_r1_hf.yml @@ -8,6 +8,7 @@ description: Description } frequency_unit: kHz + frequency_fraction_digits: 0 comments: - Source Base: 'https://www.iaru-r1.org/wp-content/uploads/2021/06/hf_r1_bandplan.pdf' - Source Base Date: "2021-06-09" diff --git a/band-plan.html b/band-plan.html index 9d4dc5e..43d4a06 100644 --- a/band-plan.html +++ b/band-plan.html @@ -125,15 +125,27 @@ div>label { return Number(number) >= Number(min) && Number(number) <= Number(max); } - function add_column(row, cols, header) { + function add_column(row, cols, header, minimum_fraction_digits = 0) { + const formatter = new Intl.NumberFormat("en-US", { + minimumFractionDigits: minimum_fraction_digits, + maximumFractionDigits: 100, + }); header.columns.forEach((col) => { if (header.columns.includes(col)) { if (typeof cols[col] === "object") { for (const [key, value] of Object.entries(cols[col])) { - row[col + "_" + key] = value; + if ((key === "frequency") && (typeof value === "number")) { + row[col + "_" + key] = formatter.format(value); + } else { + row[col + "_" + key] = value; + } } } else { - row[col] = cols[col]; + if ((col === "frequency") && (typeof cols[col] === "number")) { + row[col] = formatter.format(cols[col]); + } else { + row[col] = cols[col]; + } } } }); @@ -183,7 +195,7 @@ div>label { // then fill tdata regulations.forEach((reg) => { if ((typeof reg.header === "undefined") || (reg.header == false)) { - add_column(row, base, header["base"]); + add_column(row, base, header["base"], header["base"].frequency_fraction_digits); let [reg_start, reg_end] = reg.frequency.split("-"); reg_start = Qty(Number(reg_start), header["regulation"].frequency_unit).to(header["base"].frequency_unit).scalar; @@ -191,7 +203,7 @@ div>label { if (typeof base.frequency === "number") { // at single frequency if (isInRange(base.frequency, reg_start, reg_end)) { - add_column(row, reg, header["regulation"]); + add_column(row, reg, header["regulation"], header["base"].frequency_fraction_digits); tdata.push(row); } } else {