# 数を範囲内におさめる（Math.constrain）

> 数値を範囲内に制限します。

- カテゴリ：計算（math）
- ブロック：0 を 0 以上 0 以下の範囲に制限
- URL：https://makecode.minecraft-okinawa.com/reference/math/constrain/
- 公式データ取得日：2026-11-13
- 動作確認：確認待ち

## JavaScript

```javascript
Math.constrain(0,0,0)
```

## Python

```python
Math.constrain(0, 0, 0)
```

## 引数

| 名前 | 値 | 意味 |
|---|---|---|
| value | 数値 | 制限する値（すべてのデータ型） |
| low | 数値 | データ範囲の下限値（すべてのデータ型） |
| high | 数値 | データ範囲の上限値（すべてのデータ型） |

## 使用例

### Keep a desired value within a realistic range of 50 to 100.

```javascript
let desired = 155
let realistic = Math.constrain(desired, 50, 100)
```

```python
desired = 155
realistic = Math.constrain(desired, 50, 100)
```

## 出典

- [MakeCode for Minecraft 公式リファレンス（Math.constrain）](https://minecraft.makecode.com/reference/math/constrain)

執筆：鈴木孝昌（現役プロジェクトマネージャー／マイクラカップ指導者）／運営：沖縄マイクラ部 プログラミングスクール「クロスウェーブ」（https://minecraft-okinawa.com/）