# $19.99にサブスクリプション価格を設定できません

**URL:** https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466
**Category:** Bug
**Tags:** subscriptions
**Created:** [2026 年 1 月 14 日午後 5:44 UTC](https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466 "2026-01-14T17:44:11Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2026 年 1 月 14 日午後 5:44 UTC](https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466/1 "2026-01-14T17:44:11Z")

</div>

- Discourse-Subscriptionsを使用しています
- 製品に価格プランを追加しようとしています
- 価格ボックスに19.99と入力します（入力の動作が非常に奇妙なため、これはすでに困難です）
- 送信を試みます
- エラー「無効な整数 1998.9999999999998」を受け取ります

これまでのところ、stable 3.5.3でのみテストしましたが、betaでもコードは同じです。

[Code](https://github.com/discourse/discourse-subscriptions/blame/main/assets/javascripts/discourse/models/plan.js#L5-L13)

```plaintext
  @computed("unit_amount")
  get amountDollars() {
    return parseFloat(this.get("unit_amount") / 100).toFixed(2);
  }

  set amountDollars(value) {
    const decimal = parseFloat(value) * 100;
    this.set("unit_amount", decimal);
  }

```

Javascript / IEEE-754 floatの厄介な点:

```plaintext
-> parseFloat("19.99")*100
<- 1998.9999999999998

```

提案された修正: `const decimal = Math.round(Number(value) * 100)`

最大の疑問: なぜ誰も気づかなかったのか？誰も価格を19.99ドルに設定したことがなかったのでしょうか？

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2026 年 1 月 14 日午後 5:50 UTC](https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466/2 "2026-01-14T17:50:20Z")

</div>

> [@RGJ](#):
>
> JavaScript / IEEE-754 float の厄介な点:

すぐにわかりました。40年以上前に学んだコンピューターに関する、変わらないことの一つです。

> [@RGJ](#):
>
> 提案された修正: `const decimal = Math.round(Number(value) * 100)`

あるいは1セント単位の整数を使うか？Stripeは実際そうしていると思います。（しかし、あなたの解決策は変更するコードがはるかに少ないので、そちらが優勢でしょう。）

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2026 年 1 月 14 日午後 5:52 UTC](https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466/3 "2026-01-14T17:52:07Z")

</div>

> [@pfaffman](#):
>
> あるいは1セント単位の整数を使いますか？Stripeは実際そうしていると思います。

はい、その通りです。`unit_amount` はセント単位で、`amountDollars` は「XX.XX」形式の入力値です。  
「無効な整数」エラーはStripe APIから直接発生します。

> [@pfaffman](#):
>
> すぐにわかりました。40年以上前に学んだことですが、コンピューターに関するもので変わっていないことがもう一つありますね。

FDIVバグについて知っているくらい、私たち二人とも年季が入っているようですね :wink:

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2026 年 1 月 15 日午前 3:59 UTC](https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466/4 "2026-01-15T03:59:56Z")

</div>

正直なところ、これを float で保存するのは誤りだと思います。この列は int で、セント単位で保存されるべきです。

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2026 年 1 月 15 日午前 4:35 UTC](https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466/5 "2026-01-15T04:35:55Z")

</div>

`parseFloat` は、入力フィールド（「小数点以下2桁の通貨」）との間で変換するために使用されています。`unit_amount` オブジェクトのプロパティは明らかに型がないため、`Math.round()` の使用を提案しました。

これはサーバー側のカラムではなく、Stripe API に渡されます。

---

<div class="post-metadata">

### Author: ![Bruce5051](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bruce5051/32/426345_2.png) [@Bruce5051](https://meta.discourse.org/u/Bruce5051)
#### Post date: [2026 年 1 月 15 日午前 4:40 UTC](https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466/6 "2026-01-15T04:40:21Z")

</div>

通貨BCDでは、バイナリ浮動小数点よりもBCD浮動小数点の方が一般的に優れています。

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2026 年 2 月 17 日午前 11:11 UTC](https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466/7 "2026-02-17T11:11:12Z")

</div>

ご報告ありがとうございます、@RGJさん。これで修正されるはずです :+1:

> <https://github.com/discourse/discourse/pull/37877>
>
> Setting a subscription price like $19.99 would fail with "Invalid integer 1998.9…999999999998" from the Stripe API.
> 
> Due to IEEE-754 floating point arithmetic, \`parseFloat("19.99") \* 100\` produces \`1998.9999999999998\` instead of \`1999\`. This non-integer value is then sent directly to Stripe which rejects it.
> 
> Wrapping the multiplication in \`Math.round()\` ensures the result is always a proper integer before being stored as \`unit\_amount\`.
> 
> https://meta.discourse.org/t/393466

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2026 年 2 月 23 日午前 7:00 UTC](https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466/10 "2026-02-23T07:00:27Z")

</div>

このトピックは2日後に自動的にクローズされました。新しい返信は許可されていません。
