Skip to content

Instantly share code, notes, and snippets.

console.log(Number(Math.round(1.005 + "e2") + "e-2")) // 1.01
const roundAccurately = (number, decimalPlaces) => Number(Math.round(number + "e" + decimalPlaces) + "e-" + decimalPlaces)
console.log(roundAccurately(1.005, 2)) // 1.01
@marocas
marocas / useScroll.ts
Created October 19, 2021 22:03 — forked from gusfune/useScroll.ts
Custom React hook for listening to scroll events
import { useState, useEffect } from "react"
type SSRRect = {
bottom: number
height: number
left: number
right: number
top: number
width: number
x: number