fn
useToNumber
v0.0.15testeddemoReactively convert a string or number ref to a number.
Examples
ts
const str = ref('42.5');
const num = useToNumber(str); // 42.5ts
// custom converter and clamping
const n = useToNumber(input, { method: v => Math.round(+v), min: 0, max: 100 });Demo
Loading demo…
Signature
ts
export function useToNumber(
value: MaybeRefOrGetter<number | string>,
options: UseToNumberOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
value | MaybeRefOrGetter<string | number> | The source value (can be reactive) |
options? | UseToNumberOptions | Options |
Returns
ComputedRef<number>The numeric value