SQLServer Adapter adding digits when pulling datatype real from SQL Server 2012

19 views
Skip to first unread message

Conal Scanlon

unread,
Sep 18, 2014, 5:53:14 PM9/18/14
to rails-sqlse...@googlegroups.com
Hello,

I have a rails prod app on windows server 2012 with SQL Server 2012 backend. I did original devleopment in MySQL and then converted to SQL Server after DB was created. 

I have a lot of numerical fields, all stored as datatype "real". Everything is storing in database correctly - for instance, if use enters .615 into form, the value is saved as .615.

However, the same data can't be retrieved. In the db, the data looks like this - 


However, when retrieved from TinyTDS or the Rails application, it looks like this - 
//Turbine.find(1)
//#<Turbine id: 1, baseload_power_output: 470.0, baseload_efficien
//cy: 0.6150000095367432, duct_firing_power_output: 494.0, duct_firing_efficiency: 0.5950000286102295, minimum_load_power_
//output: 261.0, minimum_load_efficiency: 0.5619999766349792 >

Any ideas? Any help is appreciated!

KLausG

unread,
Sep 22, 2014, 5:03:55 AM9/22/14
to rails-sqlse...@googlegroups.com

Conal Scanlon

unread,
Sep 26, 2014, 12:41:42 PM9/26/14
to rails-sqlse...@googlegroups.com
Very helpful, thank you!

In case someone stumbles upon this later: to resolve this issue, I just used number_with_precision for any values in rails, and Math.round(number * 100) / 100 in JS (this should get you close enough to 2 decimal places).
Reply all
Reply to author
Forward
0 new messages