In this video it shows that how Math.round method can be used to convert the float number to the nearest integer number by rounding operation.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: [email protected]
Complete source code and other details/ steps of this video are posted in the below link:
https://programmerworld.co/android/ho...
However, the main Java code is copied below also for reference:
package com.programmerworld.floattoint;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private EditText editTextFloat;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextFloat = findViewById(R.id.editTextNumberDecimal);
textView = findViewById(R.id.textView);
}
public void buttonConvertFloatToInt(View view){
Float floatInput = Float.valueOf(editTextFloat.getText().toString());
int intOutput = Math.round(floatInput);
textView.setText(String.valueOf(intOutput));
}
}
-
On this page of the site you can watch the video online How to convert a float to int in your Android App? with a duration of hours minute second in good quality, which was uploaded by the user Programmer World 01 May 2022, share the link with friends and acquaintances, this video has already been watched 1,223 times on youtube and it was liked by 7 viewers. Enjoy your viewing!