Have you let it die? Keep waking it up, playing intensive games etc.. to KILL it. I mean to the point that it shuts off and then when you turn it back on it shuts off again. If the software running the battery is off then this should give it an absolute zero.
There are apps supposed to stress a battery but I doubt any would work at 40 percent. Most are designed for charged batteries.
I hope it's a software issue. I hope so and that you can get it to charge. What happens if you turn it off and plug it up? The flashing battery tells you how full it is. Does it just stop at 40?