add digits after comma for showing e. g. 145.500 MHz

This commit is contained in:
Wolfgang 2024-06-03 21:48:54 +02:00
parent 2395abe47d
commit 64d4f68eb3
2 changed files with 18 additions and 5 deletions

View file

@ -8,6 +8,7 @@
description: Description
}
frequency_unit: kHz
frequency_fraction_digits: 0
comments:
- Source Base: '<a href="https://www.iaru-r1.org/wp-content/uploads/2021/06/hf_r1_bandplan.pdf">https://www.iaru-r1.org/wp-content/uploads/2021/06/hf_r1_bandplan.pdf</a>'
- Source Base Date: "2021-06-09"

View file

@ -125,17 +125,29 @@ 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])) {
if ((key === "frequency") && (typeof value === "number")) {
row[col + "_" + key] = formatter.format(value);
} else {
row[col + "_" + key] = value;
}
}
} else {
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 {