usePrecision
Reactively set the precision of a number.
Usage
ts
import { usePrecision } from '@vueuse/math'
const value = ref(3.1415)
const result = usePrecision(value, 2) // 3.14
const ceilResult = usePrecision(value, 2, {
math: 'ceil'
}) // 3.15
const floorResult = usePrecision(value, 3, {
math: 'floor'
}) // 3.141
Type Declarations
typescript
export interface UsePrecisionOptions {
/**
* Method to use for rounding
*
* @default 'round'
*/
math?: "floor" | "ceil" | "round"
}
/**
* Reactively set the precision of a number.
*
* @see https://vueuse.org/usePrecision
*/
export declare function usePrecision(
value: MaybeRefOrGetter<number>,
digits: MaybeRefOrGetter<number>,
options?: MaybeRefOrGetter<UsePrecisionOptions>,
): ComputedRef<number>
Source
Contributors
Anthony Fu
Anthony Fu
德鲁叔叔
ClemDee
Changelog
Pending for release...
59f75
- feat(toValue): deprecate toValue
from @vueuse/shared
in favor of Vue's nativev12.0.0-beta.1
on 11/21/2024v10.7.0
on 12/5/2023v10.1.1
on 5/1/2023v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
0a72b
- feat(toValue): rename resolveUnref
to toValue
v9.12.0
on 1/29/2023