The problem is definitely obvious in your second picture. Do you know how modulo (%) operations work?

Let's assume the actor's HP is 6789. In your first image, 6789 is divided by 1000 which gives us 6 (in the rules of computer science and dividing integers, you ignore the decimal 0.789). You then do 6 % 1000 which still equals 6 (1000 cannot divide into 6 so the remainder, 6, is returned). Clearly, you can see this step can be removed entirely. But it did get the thousands digit, so no problems here.

Moving onto the second image and still assuming 6789, you divide 6789 by 100 and get 67. Modulo that with 100 and get 67 (again, same reasons, same redundancy). Obviously, you didn't get the 7.

To fix this, you should add another variable (call it Hero's HP) which will be set to the actor's HP. You then modulo the Actor's HP by 1000, then by 100, then by 10 to effectively reduce it and gain access to the other digits.

This is what I would do:

So using our previous example of 6789, the Thousand Digit will be set to this and divided by 1000 to get 6. You then modulo the 6789 by 1000 to get 789. Divide by 100 to get 7. Modulo it by 100 to get 89...etc.

If you want to use one less variable, you can set Hero HP to One Digit, allowing you to remove the last event line in my image above.