Ruby: (289 / 30 * 30) - (149 / 30 * 30)
150
Rest of the world: (289 / 30 * 30) - (149 / 30 * 30)
140
An explanation is greatly appreciated
1–8 of 8 posts
Ruby: (289 / 30 * 30) - (149 / 30 * 30)
150
Rest of the world: (289 / 30 * 30) - (149 / 30 * 30)
140
An explanation is greatly appreciated
Ruby does know how to do math and is doing precisely what you told it to.
289/30 is exactly 9 and 149/30 is exactly 4 because they are integer expressions. You need to specify the constants as floating point values if you want floating point behavior. Ruby does know how to do math and is doing precisely what you told it to.
289/30 is exactly 9 and 149/30 is exactly 4 because they are integer expressions. You need to specify the constants as floating point values if you want floating point behavior. Ruby does know how to do math and is doing precisely what you told it to.
thanks for the clear explanation. It's strange to me as a newbie in ruby that this can happen and I think that can lead to errors if you don't take that into account when doing calculations with numbers... Good to know
289/30 is exactly 9 and 149/30 is exactly 4 because they are integer expressions. You need to specify the constants as floating point values if you want floating point behavior. Ruby does know how to do math and is doing precisely what you told it to.
thanks for the clear explanation. It's strange to me as a newbie in ruby that this can happen and I think that can lead to errors if you don't take that into account when doing calculations with numbers... Good to know
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