跳到主要内容

usePrecision

分类
导出大小
212 B
@vueuse/math
上次更改
3 个月前

响应式地设置数字的精度。

用法

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

类型声明

ts
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 * * @__NO_SIDE_EFFECTS__ */ export declare function
usePrecision
(
value
:
MaybeRefOrGetter
<number>,
digits
:
MaybeRefOrGetter
<number>,
options
?:
MaybeRefOrGetter
<UsePrecisionOptions>,
):
ComputedRef
<number>

来源

源码文档

贡献者

Anthony Fu
Anthony Fu
NoiseFan
SerKo
IlyaL
德鲁叔叔
ClemDee

更新日志

v13.6.0
d32f8 - refactor: 为所有纯函数添加 @__NO_SIDE_EFFECTS__ 注释 (#4907)
v12.8.0
7432f - feat(types): 废弃 MaybeRefMaybeRefOrGetter,转而使用 Vue 的原生类型 (#4636)
v12.3.0
59f75 - feat(toValue): 废弃 @vueuse/shared 中的 toValue,转而使用 Vue 的原生函数
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
v10.7.0
fccf2 - feat: 升级依赖 (#3614)
v10.1.1
e83a3 - fix: 提高浮点精度 (#3024)

根据 MIT 许可证发布。