6 lines
217 B
TypeScript
6 lines
217 B
TypeScript
export default function TWUIRoundToNearestMagnitude(n: number) {
|
|
if (n === 0) return 0;
|
|
const magnitude = Math.pow(10, Math.floor(Math.log10(Math.abs(n))));
|
|
return Math.round(n / magnitude) * magnitude;
|
|
}
|