1 year ago

#388389

test-img

000723-weict

Bigdecimal value not converting to Integer value in Rails 4

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.

javascript

mysql

sql

ruby-on-rails

ruby-on-rails-4

0 Answers

Your Answer

Accepted video resources