I worry you’re not on the right track here. Take a look at Coordinate System - Rotation Conventions. I would question why you don’t want the values to be in the range (-180, 180].
More importantly, NavX rotation is CW+, which is the opposite of the convention used by other WPILib classes. You probably either want to use getRotation2d(), which inverts the value for you, or you want to invert the returned value from getAngle() or getYaw().
From our 2022 robot’s code:
public double getHeading() {
return Math.IEEEremainder(gyro.getAngle(), 360.0d) * -1.0d;
}