JavaScript
const toFixed = (n, fixed) => `${n}`.match(new RegExp(`^-?\\d+(?:\.\\d{0,${fixed}})?`))[0]
const toFixed = (n, fixed) => ~~(Math.pow(10, fixed) * n) / Math.pow(10, fixed)
TypeScript
const toFixed = (n: number, fixed: number): number => +(`${n}`.match(new RegExp(`^-?\\d+(?:\.\\d{0,${fixed}})?`)) as string[])[0]
const toFixed = (n: number, fixed: number): number => ~~(Math.pow(10, fixed) * n) / Math.pow(10, fixed)
Examples
toFixed(25.198726354, 1)
toFixed(25.198726354, 2)
toFixed(25.198726354, 3)
toFixed(25.198726354, 4)
toFixed(25.198726354, 5)
toFixed(25.198726354, 6)