Content stream number writer
64-bitFormats one number for a PDF content stream.
text = toFixed(v, 4) without trailing zeros
The saved coordinate is rounded to 4 decimals (0.0001 pt, about 0.035 micrometer). Values under 5e-5 and negative zero become 0, and NaN or Infinity are written as 0 with no warning.
/** A number as a content stream writes it (no exponent, at most 4 decimals). */
export function num(v) {
if (!Number.isFinite(v)) return '0';
const s = (Math.abs(v) < 5e-5 ? 0 : v).toFixed(4).replace(/\.?0+$/, '');
return s === '-0' ? '0' : s;
}