# setValueToStep()

## `Range.prototype.setValueToStep()`

The method `setValueToStep()` sets the [value](https://range.angular-package.dev/draft/range/methods/pages/K3Di7Lb1PzkbEN0Iwo3M#range.prototype.value) of the specified [`Range`](/draft/range/overview.md) object to the value of the given [`step`](#step-number).

{% hint style="warning" %}
If the given [`step`](#step-number) is not within range the [`value`](/draft/range/accessors/value.md) is not changed.
{% endhint %}

{% code title="range.class.ts" %}

```typescript
public setValueToStep(step: number): this {
  step > 0 && (this.value = this.getValueOfStep(step));
  return this;
}
```

{% endcode %}

### Parameters

#### `step:`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)

Step of [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) type to retrieve the value from the range and set it as the range current [`value`](/draft/range/accessors/value.md).

### Return type

#### [<mark style="color:green;">`this`</mark>](/draft/range/overview.md)

### Returns

The **return value** is the [`Range`](/draft/range/overview.md) instance.

## Example usage

```typescript
// Example usage.
import { Range } from '@angular-package/range';

// Create new instance.
// Returns Range {min: 3, max: 27, value: 10} of Range<3, 27, 3>.
const range = new Range(3, 27, 10, 3);

// Cannot assign to 'value' because it is a read-only property.ts(2540)
// range.value = 12;

// Returns 9 of type number | undefined.
range.setValueToStep(3).value;

// Returns 27 of type number | undefined.
range.setValueToStep(9).value;

// Returns undefined of type number | undefined.
range.setValueToStep(11).value;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://range.angular-package.dev/draft/range/methods/setvaluetostep.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
