Skip to content

usePrecision

Category
Export Size
240 B
Package
@vueuse/math
Last Changed
2 months ago

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

SourceDocs

Contributors

Anthony Fu
Anthony Fu
德鲁叔叔
ClemDee

Changelog

v10.7.0 on 12/5/2023
fccf2 - feat: upgrade deps (#3614)
v10.1.1 on 5/1/2023
e83a3 - fix: improve flooting point accuracy (#3024)
v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
0a72b - feat(toValue): rename resolveUnref to toValue
v9.12.0 on 1/29/2023
e331b - fix: fix return type (#2676)

Released under the MIT License.