Enter M501 in the control software of your choice. This will show the current stored settings on your firmware.
The section we are looking for begins with, M92. This sets the number of steps which, in turn controls the accuracy of our printer.
To Calculate Accurate Steps
( Distance to Travel / Distance Traveled ) * Number of Configured Steps
For example, on the (40 / 39.90) * 84.40.
This gives new steps of 84.612 ( we only need a few places of accuracy, the real calculation gives more).
Enter this with the command M92 X84.612 (Make sure the letters are capitalized)
Step 2 Measuring
We need to measure the amount of filament the extruder is pushing through to make sure we don't over extrude. Mark the filament, with a piece of tape or post-it.
Place a flag of tape 100mm above the extruder.
Extrude 50mm of filament.
Measure the distance from the top of the extruder to the 'flag' of tape, to see how much filament was extruded.
Use the formula above (amount told to extrude/real amount extruded) multiplied by Number of steps in firmware.
Type the new value with M92 Exxx
Save all the settings with M500 and M501 to check the new settings.
Repeat until you get the exact extrusion length you asked to print out.
You can also do this with a 100mm, but measure out to 150mm and extrude 100mm of filament to see if it changes, if so, repeat the steps above until it's accurate.