Better HN
topnewbestaskshowjobs
Log inSign up

Dajve_Bloke

1 karma · joined Jun 28, 2019 (7y ago) · 2 submissions

Submissions

comment 7y ago · link · parent

NB - you get the same result in MS-SQL (and for exactly the same reason).

Ruby behaves like SQL in that appending a decimal to the values results in non-integer maths being employed.

MS-SQL itself is slightly out (I assume due to floating point inaccuracy)

SELECT (289.0 / 30.0 * 30.0) - (149.0 / 30.0 * 30.0) 140.0000100

comment 7y ago · link · parent

289/30 = 9 as it's truncating the non-integer part of the operation. So the calculation evaluates to 270 - 120 = 150