Fix rounding to 0
This commit is contained in:
@@ -10,7 +10,13 @@ export interface SolveResult {
|
||||
}
|
||||
|
||||
function fmt(n: number): string {
|
||||
return parseFloat(n.toFixed(6)).toString();
|
||||
if (!Number.isFinite(n)) return n.toString();
|
||||
if (n === 0) return '0';
|
||||
if (Math.abs(n) < 1e-6) {
|
||||
return n.toExponential(6);
|
||||
}
|
||||
const rounded = parseFloat(n.toFixed(6));
|
||||
return rounded.toString();
|
||||
}
|
||||
|
||||
function gcd(a: number, b: number): number {
|
||||
|
||||
Reference in New Issue
Block a user