コンテンツへスキップ

usePrecision

カテゴリ
エクスポートサイズ
240 B
パッケージ
@vueuse/math
最終更新日
先週

数値の小数点以下の桁数をリアクティブに設定します。

使用方法

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>

ソース

ソースドキュメント

コントリビューター

Anthony Fu
Anthony Fu
德魯叔叔
ClemDee

変更ログ

v12.0.0-beta.1 2024/11/21
0a9ed - feat!: Vue 2サポートの削除、バンドルの最適化、クリーンアップ (#4349)
v10.7.0 2023/12/5
fccf2 - feat: 依存関係のアップグレード (#3614)
v10.1.1 2023/5/1
e83a3 - fix: 浮動小数点数の精度向上 (#3024)
v10.0.0-beta.4 2023/4/13
4d757 - feat(types)!: MaybeComputedRef の名前を MaybeRefOrGetter に変更
0a72b - feat(toValue): resolveUnref の名前を toValue に変更
v9.12.0 2023/1/29
e331b - fix: 戻り値の型の修正 (#2676)

MITライセンスの下でリリースされています。