Well, for starters, what is your tap water pH & kH? (you might want to check your nitrates just for giggles, too...)
Best way to measure that is get a 5 gallon bucket, fill it with water, add some Prime, wait a minute or two, and check your pH. Is that lower or higher than what's in your tank?
There are buffer recipes in the library here on the forum. How much you use will depend on how much buffer you need to raise the pH in your 5 gallon bucket to the desired level.
What is the desired level you want to reach in that 5 gallon bucket? Get out your calculator... there will likely be some math involved...
You have a 40 gallon tank. Your pH is 6.2. You want to do a 50% water change (20 gallons). You want the end result in your tank to be (baby steps here in case we miscalculate some) say, 6.4. Now, back to your 5 gallon bucket. Let's say that from wherever the pH is (assuming your tap is the same as your tank, which may NOT be) you want to get that 5 gallon bucket up to pH 6.6. It might take a 1/2 teaspoon of buffer or it might take much more. This is why you're adding it to the bucket first...

Mix it in the bucket, wait 30 minutes or so, and then measure the pH. So if we really screw something up, we don't hurt the fish...
So, let's say that you have determined that "x" amount of buffer raises 5 gallons of your source water from 6.2 to 6.6. Then "x times 4" will be the approximate amount needed for a 20 gallon water change. Why do I say approximate? Because kH affects how easily pH can change. At least this will give you a place to start. The higher the kH, the more resistant pH is to change. Yes, black magic & voodoo seem to be involved,
which is why you must experiment. I don't think anyone can tell you for sure exactly how much to use.
And to be even safer, use
half the amount the first time to be sure.
I never understand people recommending not to do larger water changes if the water is bad... I do two 60-70% water changes per week. Bad water needs to go. 40 nitrates is too high. Although, there are two things that can get you into trouble with bigger water changes - primarily big swings in pH and kH... which can contribute to swings in pH...
But please! BEFORE you take my advice... wait for someone with more experience than me to chime in and verify that this is a sane course of action. Here is the buffer recipe -
http://www.cichlid-forum.com/articles/buffer_recipe.php
Hope this helps!