-2

My problem is just the decimal number format. I am a beginner and I do not know how to resolve the problem. I think I should use decimal format, but I do not know how to use it.

And here is my java code:

public class MainActivity extends Activity implements SensorEventListener {

    @Override
    public void onSensorChanged(SensorEvent event) {

        // get the angle around the z-axis rotated
        float degree = event.values[0];
        tvHeading.setText(Float.toString(degree) + "°");

        // create a rotation animation (reverse turn degree degrees)
        RotateAnimation ra = new RotateAnimation(
                currentDegree, -degree,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);

        // how long the animation will take place
        ra.setDuration(210);

        // set the animation after the end of the reservation status
        ra.setFillAfter(true);

        // Start the animation
        image.startAnimation(ra);
        currentDegree = -degree;
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        // not in use
    }
}
Roland Szép
  • 879
  • 1
  • 8
  • 19

1 Answers1

1

Assuming this is the problem that you are referring to:

// get the angle around the z-axis rotated
float degree = event.values[0];
tvHeading.setText(Float.toString(degree) + "°");

Round the result to the nearest integer:

// get the angle around the z-axis rotated
float degree = event.values[0];
tvHeading.setText(Math.round(degree) + "°");
Ian
  • 1,475
  • 2
  • 15
  • 31