Skip to main content
You are viewing Pre-Alpha documentation.
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. Snap to step, clamp to range, convert between values and percentages, with floating-point precision correction.


IntermediateApr 4, 2026

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

50
50% of range
<script setup lang="ts">
  import { createNumeric } from '@vuetify/v0'
  import { shallowRef } from 'vue'

  const numeric = createNumeric({ min: 0, max: 100, step: 5 })
  const value = shallowRef(50)
</script>

<template>
  <div class="flex flex-col items-center gap-4">
    <div class="flex items-center gap-2">
      <button
        class="px-3 py-1 rounded border"
        :disabled="!numeric.canDown(value)"
        @click="value = numeric.down(value)"
      >
        −
      </button>

      <span class="w-16 text-center text-2xl font-bold tabular-nums">
        {{ value }}
      </span>

      <button
        class="px-3 py-1 rounded border"
        :disabled="!numeric.canUp(value)"
        @click="value = numeric.up(value)"
      >
        +
      </button>
    </div>

    <div class="text-sm opacity-60">
      {{ numeric.fromValue(value).toFixed(0) }}% of range
    </div>
  </div>
</template>

API Reference

The following API details are for the createNumeric composable.

Functions

createNumeric

(options?: NumericOptions) => NumericContext

Options

min

number | undefined

Minimum value.

Default: -Infinity

max

number | undefined

Maximum value.

Default: Infinity

step

number | undefined

Step increment for Arrow keys.

Default: 1

leap

number | undefined

Large step for PageUp/PageDown.

Default: step * 10

wrap

boolean | undefined

Circular wrapping (max+step → min).

Default: false

Properties

min

number

max

number

step

number

leap

number

wrap

boolean

Methods

snap

(value: number) => number

fromValue

(value: number) => number

fromPercent

(percent: number) => number

up

(value: number, multiplier?: number) => number

down

(value: number, multiplier?: number) => number

floor

() => number

ceil

() => number

canUp

(value: number) => boolean

canDown

(value: number) => boolean
Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/