usePrecision
响应式地设置数字的精度。
用法
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
类型声明
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.cn/usePrecision
*/
export declare function usePrecision(
value: MaybeRefOrGetter<number>,
digits: MaybeRefOrGetter<number>,
options?: MaybeRefOrGetter<UsePrecisionOptions>,
): ComputedRef<number>
源码
贡献者
更新日志
v12.8.0
于 2025/3/5v12.3.0
于 2025/1/259f75
- feat(toValue): 弃用来自 @vueuse/shared
的 toValue
,转而支持 Vue 的原生v12.0.0-beta.1
于 2024/11/21v10.7.0
于 2023/12/5v10.1.1
于 2023/5/1v10.0.0-beta.4
于 2023/4/134d757
- feat(types)!: 将 MaybeComputedRef
重命名为 MaybeRefOrGetter
0a72b
- feat(toValue): 将 resolveUnref
重命名为 toValue
v9.12.0
于 2023/1/29