Skip to main content
Vuetify0 is now a release candidate!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

createNumeric

Pure numeric math for bounded values with step snapping, range clamping, and floating-point precision correction.

Usage

ts
import { createNumeric } from '@vuetify/v0'

const numeric = createNumeric({ min: 0, max: 100, step: 5 })

numeric.snap(47)        // 45
numeric.snap(48)        // 50
numeric.up(50)          // 55
numeric.down(50)        // 45
numeric.floor()         // 0
numeric.ceil()          // 100
numeric.fromValue(50)   // 50 (percentage)
numeric.fromPercent(33) // 30 (snapped value)
numeric.canUp(100)      // false
numeric.canDown(0)      // false

Architecture

Diagram

Use controls to zoom and pan. Click outside or press Escape to close.

Reactivity

createNumeric is a pure function factory — it returns plain functions, not reactive refs. This makes it composable with any reactive system.

MethodReturnsDescription
snap(value)numberRound to nearest step, clamp to [min, max]
up(value, multiplier?)numberIncrement by step × multiplier
down(value, multiplier?)numberDecrement by step × multiplier
floor()numberReturn min value
ceil()numberReturn max value
fromValue(value)numberConvert value to 0–100 percentage
fromPercent(percent)numberConvert percentage to snapped value
canUp(value)booleanWhether increment is possible
canDown(value)booleanWhether decrement is possible

Examples

Bounded Stepper

A counter (0–100, step 5) wired to createNumeric with boundary guards and a live percentage readout. Because createNumeric returns plain functions rather than reactive refs, the example keeps its own shallowRef<number> for the current value and calls numeric.up(value) / numeric.down(value) on click — each returns the next snapped value and the template re-renders automatically when value changes.

canDown and canUp return false at the boundaries (0 and 100), which the :disabled bindings map directly to button state. The fromValue(value) call converts the current value to a 0–100 percentage for the display below the counter, demonstrating that createNumeric is equally useful for display derivation, not just mutations.

This composable has no opinions about where the value lives — the same numeric instance could serve multiple independent counters simultaneously. Reach for createSlider when you need registered thumbs, percentage-to-value conversion from pointer events, and reactive values; use createNumberField when you need Intl formatting and field validation on top of the same math.

50
50% of range

FAQ

Discord
Need help? Join our community for support and discussions ↗

API Reference

The following API details are for the createNumeric composable.
Was this page helpful?

Ctrl+/