Spine is indeed rendering your animation at the requested 24 FPS and the export having 32 frames is correct. This is why:
The timeline FPS defaults to 30. You say you have an animation that is 40 frames. Those 40 frames at a timeline FPS of 30 is 40 / 30 = 1.33 seconds long. If you export your 1.33 second animation at 24 FPS you get 1.33 * 24 = 32 frames.
If you want to have a frame in your export for every frame you see in the Spine timeline, then you'll need to use the same FPS when exporting as you have set for the timeline FPS. If you change the timeline FPS, you'll change the speed of your animation. You can then box select all the keys and drag the box selection edge to scale, or you can use this approach to adjust all your animations at once:
Reducing frames by 25%.