ArcRotateCamera setPosition is different from the actual value

Modify the position of ArcRotateCamera through setPosition, and then generate an error in the value of get position.z

Can’t see any error here. The arc rotate camera does not have x,y or z since it’s ment for use with a target. The position of the camera is calculated from the target and the values you want to get is alpha (for horizontal rotation or x), beta (for vertical rotation or y) and radius (for depth, z, or zoom), put it the way you want.
So if you want to get the distance from your target, it shall be ‘camera.radius’

Edit: And the small difference comes from the translation to an orbital camera with the beta value creating an error if it’s set to zero or Math.PI (as described here).