# 无法将订阅价格设置为 $19.99

**URL:** <https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466>\
**Category:** Bug\
**Tags:** subscriptions\
**Created:** [2026年一月14日 17: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:** 1\
**Showing post:** 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年一月14日 17: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”

我只在稳定版 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 浮点数怪癖：

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

```

建议的修复方法：`const decimal = Math.round(Number(value) * 100)`

我最大的疑问是：为什么没有人注意到？以前没有人将价格设置为 19.99 美元吗？

---

_[View the full topic](https://meta.discourse.org/t/unable-to-set-subscription-price-to-19-99/393466)._
