How To Make Rails Json Output Decimal Numbers Instead Of Strings

18-Sep-2016 3384

Working on an application I noticed that when getting JSON data from Rails the decimal numbers come as strings. Turns out this is to ensure it is still accurately rounded.If you don’t care about the rounding of large numbers then you can force Rails to output the decimals as numbers.

Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle