When extracting the rotation tag from the NBT, a number between 0 to 360 is returned..
However, When passing the real 0 rotation in the code(not the wrapped one that is in F3), The NBT value goes to minus and displays a wrong number..
Fix:
The NBT tag for rotation needs the same wrapper that F3 uses, and adding 180 to the number before passing it to the NBT, That way it'll be really a number between 0 to 360
Linked issues
Comments

Yes Neko, Thanks! I was searching for it before posting using a few keywords and couldnt find it..
Does MC-121855 describe your issue?