export function formatValue(v: number | null, unit: string) {
  if (v == null || !Number.isFinite(v)) return '—'
  // 简易工程计数法
  const absv = Math.abs(v)
  const units = [
    { s: 1e-9, u: 'n' },
    { s: 1e-6, u: 'µ' },
    { s: 1e-3, u: 'm' },
    { s: 1, u: '' },
    { s: 1e3, u: 'k' },
    { s: 1e6, u: 'M' },
  ]
  let u = ''
  let val = v
  for (let i = units.length - 1; i >= 0; i--) {
    if (absv >= units[i].s) { u = units[i].u; val = v / units[i].s; break }
  }
  return `${val.toFixed(3)} ${u}${unit}`
}