What's the deal with letter grades in Japanese culture?

So I was listening to episode 146 of the Video Games Hotdog podcast and Zack was musing about why Japanese seem to affix a letter grade to everything. In this situation, he noticed that weapons in Dark Souls and Bravely Default would have a letter grade to indicate how good it is. And I'm sure we've all played a Japanese game where you got a letter grade that goes all the way up to S ranking.

Even Lock Seeds in Gaim have a D to S ranking.

Anyone know why this came to be or where it came from?