Ruby Datamapper 存储以科学记数法显示的小数

发布于 2024-09-24 20:11:04 字数 388 浏览 1 评论 0原文

我有一个模型,称为交付:

property :id,           Serial
property :created_at,   DateTime
property :updated_at,   DateTime

property :price, BigDecimal,    :precision => 10, :scale => 2

交付有一个价格,在 SQLite 中查看时,其值为 5.49、6.95、4.95

当在输出中显示此信息(以 haml 编码)时,delivery.price 中的值显示为 0.695 E1、0.495E1 等

知道为什么它们以这种格式显示,以及如何最好地“正确”显示它们。

感谢所有帮助!

I have a model, called delivery:

property :id,           Serial
property :created_at,   DateTime
property :updated_at,   DateTime

property :price, BigDecimal,    :precision => 10, :scale => 2

Delivery has a price, which when viewed in SQLite is values such as 5.49, 6.95, 4.95

When displaying this information in the output (coded in haml), the values from delivery.price are displayed like 0.695E1 , 0.495E1 etc

Any idea why they are showing in this format, and how best to display them 'correctly.

All help is appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百合的盛世恋 2024-10-01 20:11:04

转换为字符串 (BigDecimal#to_s) 采用格式参数:

>> n = BigDecimal.new('5.49')
=> #<BigDecimal:100502958,'0.549E1',18(18)>
>> n.to_s
=> "0.549E1"
>> n.to_s('F')
=> "5.49"

Conversion to string (BigDecimal#to_s) takes a format parameter:

>> n = BigDecimal.new('5.49')
=> #<BigDecimal:100502958,'0.549E1',18(18)>
>> n.to_s
=> "0.549E1"
>> n.to_s('F')
=> "5.49"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文