We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The average salary is actually 4046.75 - the reason you see 4046 is because salary's data type is int, so if you pass in an int, you'll get an int back truncating the decimal portion, but if you cast to a float/decimal before averaging, you'll get the correct value back, which would then affect your later results when rounding yielding the correct answer.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Blunder
You are viewing a single comment's thread. Return to all comments →
The average salary is actually 4046.75 - the reason you see 4046 is because salary's data type is int, so if you pass in an int, you'll get an int back truncating the decimal portion, but if you cast to a float/decimal before averaging, you'll get the correct value back, which would then affect your later results when rounding yielding the correct answer.