B
B
Bogdan2017-08-07 11:35:33
Ruby on Rails
Bogdan, 2017-08-07 11:35:33

BigDecimal + as_json() = String?

Hello. It's best to do it in as_json() with BigDecimal in String.
and then I get the following result

{"count_plan"=>#BigDecimal:a639408,'0.2E1',9(18)}

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2017-08-07
@bogdan_uman

This is the case when pretty-printing objects in Ruby, useful for debugging.
And to serialize to JSON, a string should be used myobj.to_json.

h = {b: BigDecimal.new('12.34'), s: 'string'}
puts h.to_json

Shows
{"b":"12.34","s":"string"}
Apparently, the name as_json is confusing, because people think that the output will be a string in JSON format. And this is not so.
https://stackoverflow.com/questions/38301957/diff...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question