BigDecimal值不转换为铁轨中的整数值4

发布于 2025-01-19 19:28:12 字数 833 浏览 2 评论 0原文

我正在Ruby在Rails应用程序上使用V2 API响应。 当前,当我在Localhost上击中我的应用程序时:3000会根据提供的所有响应。

关键之一是百分比,其值为56.3,但我需要将其值舍入56

和V2 API仅在特殊令牌和API键的帮助下运行。

以下是我在v2/student_controller.rb中的一条代码线的态度(我不能陶醉其他代码

@result_hash = Student.fetch_by_class(params, student_ids, current_api_client.client, student_type, Mode)

results = Rails.cache.fetch("fetch_by_class_cache_#{Mode}_#{student_type}_#{client.id}", expires_in: 1.day) do
  results = Student.integral.visible.shareable
end

) :学生的关系。

现在在此Hash 结果[:百分比] = 0.6e2中,是否有一类BigDecimal。

还有多个记录,我需要将所有百分比记录更新为无小数点。类似于此结果[:百分比] = 60

这是我的代码是

results.each do |result|
    result.percentage = result.percentage.round
end

不更新并返回响应的。另外,我不想更新或将其保存在DB中。

I am working with my V2 API response on ruby on rails app.
Currently when I hit my app on localhost:3000 it gets all the response as per provided.

One of key is Percentage and its value is 56.3 but I need to round off the value to 56

And V2 API only runs with help of special token and api key.

Below is my one peice of line of code in v2/student_controller.rb (I cannot revel other code)

@result_hash = Student.fetch_by_class(params, student_ids, current_api_client.client, student_type, Mode)

This hits to my model student.rb and here is some code for understanding

results = Rails.cache.fetch("fetch_by_class_cache_#{Mode}_#{student_type}_#{client.id}", expires_in: 1.day) do
  results = Student.integral.visible.shareable
end

Here it fetches all records and It create an Active:Record::Relation of Student.

Now inside this hash results[:percentage]=0.6e2 is there which has class of Bigdecimal.

Also there are multiple records and I need to update all records of percentage to without decimal points. Similar to this results[:percentage]=60

Here Is what my code is

results.each do |result|
    result.percentage = result.percentage.round
end

This doesnt update and return the response. Also I dont want to update or save this in my DB.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文