R
fn

useRound

v0.0.15testeddemo

Reactive `Math.round` with optional decimal-place precision

Examples

ts
const value = ref(0.6);
const rounded = useRound(value); // 1
ts
const value = ref(1.2345);
const rounded = useRound(value, { digits: 2 }); // 1.23
ts
const value = ref(0.5);
const rounded = useRound(() => value.value); // 1

Demo

Loading demo…

Signature

ts
export function useRound(value: MaybeRefOrGetter<number>, options: UseRoundOptions ={ ... }

Parameters

ParameterTypeDescription
valueMaybeRefOrGetter<number>The value to round
options?UseRoundOptionsRounding options

Returns

ComputedRef<number>A computed ref of the rounded value