If you successfully win any battle against a Trainer, you get 5% of the current Reputation score of your opponent added to your own Reputation score - so an opponent with 20 Rep gives 1 Rep to you. This is usually rounded to about two decimal places, but this is not always the case, resulting in some players having really weird non-whole Rep scores. The numbers are still taken at face value though and thus don't have an actual effect on the game - it's just not very visually appealing. So basically, if you have a weird Rep score, don't worry about it too much.
I am not sure if the loser loses Reputation (this WAS part of the original plan but I don't recall if it was ever implemented); but an opponent who disconnects DOES receive a penalty. NPCs don't "technically" have a Rep Score - the amount they give is actually set in the database - but it's become a standard for the game to assume most have a Rep Score of 4, hence why you get 0.2 by beating them - of course, the Gym Leaders have MUCH more.