Skip to content

useTrunc

Category
Export Size
65 B
Package
@reause/math
Last Changed
5 days ago

Truncates a number, removing the fractional digits toward zero

Demo

Usage

tsx
import { 
useTrunc
} from '@reause/math'
const
result1
=
useTrunc
(0.95) // 0
const
result2
=
useTrunc
(-2.34) // -2

value is a plain read-only number. Re-render with a new value — e.g. from useState — and the hook recomputes:

tsx
import { 
useTrunc
} from '@reause/math'
import {
useState
} from 'react'
const [
value
,
setValue
] =
useState
(0.95)
const
result
=
useTrunc
(
value
) // 0
setValue
(-2.34) // triggers a re-render

Type Declarations

ts
export function useTrunc(value: number): number

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
35787 - fix(math): resolve useTrunc audit findings (#794)
c5a59 - feat(math): add useTrunc (#241)

Released under the MIT License. v0.1.8