# Number — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/number

Category: Data & content

Displays and formats a numeric value with options for rounding, shorthand notation, separators, dynamic coloring based on value, and an optional progress bar.

Public component import: `Number`

Public manager import: `create_number_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Number, create_number_manager } from "sveltekit-ui"

  const manager = create_number_manager({
    val: 12500,
    separators: "thousands_commas_period",
  })
</script>

<p>Monthly visitors: <Number {manager} /></p>
```

## Configuration

### `val`

- type: number or null
- default: null
- description: Initial numeric value to display. If null, displays as empty or default.

### `round`

- type: string
- default: null
- allowed_values:
  - nearest
  - floor
  - ceil
  - precision
- description: Determines the rounding method applied to the value.

### `round_by`

- type: number
- default: null
- description: Value to round to when `round` is 'nearest', 'floor', or 'ceil'.

### `precision`

- type: number
- default: null
- description: Number of significant digits when `round` is 'precision'.

### `shorthand`

- type: string
- default: null
- allowed_values:
  - thousands
  - millions
  - billions
  - trillions
  - quadrillions
- description: Applies shorthand notation to the number, adding suffixes like K, M, B, etc.

### `separators`

- type: string
- default: null
- allowed_values:
  - thousands_commas_period
  - thousands_periods_comma
- description: Formats the number with thousands and decimal separators based on locale.

### `is_percentage`

- type: boolean
- default: false
- description: If true, appends a '%' sign to the displayed number.

### `is_dynamic_color`

- type: boolean
- default: false
- description: If true, changes the color of the number based on its value relative to start and end values.

### `start_value`

- type: number
- default: null
- description: Starting value for dynamic color calculations.

### `end_value`

- type: number
- default: null
- description: Ending value for dynamic color calculations.

### `start_color`

- type: object
- default: null
- description: Starting color in Hue-Chroma format for dynamic color calculations (e.g., { h: 10, c: 10 }).

### `end_color`

- type: object
- default: null
- description: Ending color in Hue-Chroma format for dynamic color calculations (e.g., { h: 350, c: 10 }).

### `base_color`

- type: object
- default: null
- description: Base color used when dynamic color is not enabled (e.g., { h: 10, c: 10 }).

### `is_progress_bar`

- type: boolean
- default: false
- description: If true, displays the number as part of a progress bar.

### `is_hide_number`

- type: boolean
- default: false
- description: If true, hides the numeric text display.

## Methods

### `init()`

- description: Initializes the number formatting based on configuration, including rounding, shorthand, separators, dynamic color, and progress bar calculations.

### `round_value()`

- description: Rounds the numeric value based on the specified method and parameters.

### `apply_shorthand()`

- description: Applies shorthand notation to the number, converting large numbers into K, M, B, etc.

### `format_separators()`

- description: Formats the number with thousands and decimal separators based on the specified locale.

### `set_val()`

- description: Sets a new value for the number and updates its formatting accordingly.

### `set_loading_i()`

- description: Sets the thumb index to display a loading state.

### `set_hovered_i()`

- description: Sets the thumb index that is currently hovered.

### `set_error_i()`

- description: Sets the thumb index that has an error.

### `set_min()`

- description: Updates the slider's minimum bound.

### `set_max()`

- description: Updates the slider's maximum bound.

### `set_step()`

- description: Updates the slider's step increment value.

### `set_thumbs()`

- description: Updates the positions of the thumbs based on the current values.

## Returned state

### `val`

- type: object
- description: Formatted value with properties including val, val_text, suffix, font_weight, font_color, hue, chroma, and percentage_fill.
