An example of android converting float into Int

  • 2021-09-20 21:25:13
  • OfStack

1. Adopt the method of strong rotation


float a = 1.1L; // Definition 1 A float Type variable named a, Value is 1.1 , L Representation is floating-point 
int b = (int)a;// Use (int) Cast to integer type b

2. Adopt Math. round mode


float a = 1.1L; // Definition 1 A float Type variable named a, Value is 1.1 , L Representation is floating-point 
int b = Math.round(a);// Adopt round Mode to integer type 

Related articles: