---
schema_version: "1"
id: a74e81ce9c440a6f84a58a97685e0f4ae3e139e63bb25aa396b30affa4ac4d11
title: toNumber
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.7/dw-coercions-functions-tonumber.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.7/dw-coercions-functions-tonumber
source_site: docs.mulesoft.com
content_type: documentation
content_hash: d4a04488e65113b1a6a41498c399a6587c70ee32bd8f4b2d52cd5dcc00b6fccc
description: MuleSoft Documentation Site
release: "2.7"
latest: false
---
# toNumber

## [](#tonumber1)toNumber(dateTime: DateTime, unit: MillisOrSecs | Null = null): Number

選択した単位に応じて ​`DateTime`​ 値を秒数またはミリ秒数に変換する ​`toNumber`​ のバリエーション。

_DataWeave バージョン 2.4.0 で導入されました。_

### [](#パラメーター)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>dateTime</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Number</code>​ 値に変換する ​<code>DateTime</code>​ 値。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>unit</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">使用する時間の単位 (​<code>"milliseconds"</code>​ または ​<code>"seconds"</code>​)。​<code>null</code>​ 値の場合、​<code>"seconds"</code>​ が使用されます。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、さまざまな入力での ​`toNumber`​ の動作を示します。

#### [](#ソース)ソース

```DataWeave
%dw 2.0
import * from dw::util::Coercions
output application/json
---
{
    epoch: toNumber(|2015-10-01T23:57:59Z|),
    millis: toNumber(|2015-10-01T23:57:59Z|, "milliseconds")
}
```

#### [](#出力)出力

```DataWeave
{
  "epoch": 1443743879,
  "millis": 1443743879000
}
```

## [](#tonumber2)toNumber(period: Period, unit: PeriodUnits | Null = null): Number

`Period`​ 値を時間数、分数、秒数、ミリ秒数、またはナノ秒数 (​`nanos`​) に変換する ​`toNumber`​ のバリエーション。

_DataWeave バージョン 2.4.0 で導入されました。_

### [](#パラメーター-2)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>period</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Number</code>​ 値に変換する ​<code>Period</code>​ 値。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>unit</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">指定された ​<code>period</code>​ に適用する単位: <code>hours</code>​、​<code>minutes</code>​、​<code>seconds</code>​、​<code>milliseconds</code>​、または ​<code>nanos</code>​。</p></td>
</tr>
</tbody>
</table>

### [](#例-2)例

次の例では、さまざまな入力での ​`toNumber`​ の動作を示します。

#### [](#ソース-2)ソース

```DataWeave
%dw 2.0
import * from dw::util::Coercions
output application/json
---
{
    toSecondsEx1: toNumber(|PT1H10M|, "seconds"),
    toSecondsEx2: toNumber(|PT1M7S|, "milliseconds")
}
```

#### [](#出力-2)出力

```Json
{
  "toSecondsEx1": 4200,
  "toSecondsEx2": 67000
}
```

## [](#tonumber3)toNumber(value: String | Key, format: String | Null = null, locale: String | Null = null): Number

`String`​ 値または ​`Key`​ 値を ​`Number`​ 値に変換して、形式とロケールを受け入れる ​`toNumber`​ のバリエーション。

_DataWeave バージョン 2.4.0 で導入されました。_

### [](#パラメーター-3)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>value</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Number</code>​ 値に変換する ​<code>String</code>​ 値または ​<code>Key</code>​ 値。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>format</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>value</code>​ に適用する省略可能な書式設定。
           ​<code>format</code>​ は ​<em>10 進数</em>​値および ​<code>10</code>​ 未満の 1 つの整数のプレースホルダーとして ​<code>#</code>​ または ​<code>0</code>​ (ただし両方ではない) を受け入れます。1 つの小数点しか使用できません。​<code>null</code>​ 値または空の ​<code>String</code>​ 値は ​<code>Number</code>​ 値に対して無効です。他の文字を使用するとエラーが発生します。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>locale</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">使用する省略可能な ISO 3166 国コード (​<code>US</code>​、​<code>AR</code>​、​<code>ES</code>​ など)。​<code>null</code>​ または欠落値では JVM のデフォルトが使用されます。</p></td>
</tr>
</tbody>
</table>

### [](#例-3)例

次の例では、さまざまな入力での ​`toNumber`​ の動作を示します。

#### [](#ソース-3)ソース

```DataWeave
%dw 2.0
import * from dw::util::Coercions
var myKey = keysOf({"123" : "myValue"})
output application/json
---
 {
     "default": toNumber("1.0"),
     "withFormat": toNumber("0.005",".00"),
     "withLocal": toNumber("1,25","#.##","ES"),
     "withExtraPlaceholders": toNumber("5.55","####.####"),
     "keyToNumber": toNumber(myKey[0])
 }
```

#### [](#出力-3)出力

```Json
{
  "default": 1.0,
  "withFormat": 0.005,
  "withLocal": 1.25,
  "withExtraPlaceholders": 5.55,
  "keyToNumber": 123
}
```