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.dokyumento.jp/usePrecision
*/
export declare function usePrecision(
value: MaybeRefOrGetter<number>,
digits: MaybeRefOrGetter<number>,
options?: MaybeRefOrGetter<UsePrecisionOptions>,
): ComputedRef<number>
ソース
コントリビューター
変更ログ
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