Is there any function returns only the real number without the floating point? For an example,
func(1.xxx)->1
func(52.xx)->52
func(0.xx)->0
Is there any function does so?
Is there any function returns only the real number without the floating point? For an example,
func(1.xxx)->1
func(52.xx)->52
func(0.xx)->0
Is there any function does so?
Simply casting to int would truncate everything past the decimal point.
float f1 = 10.345;
int i1 = (int) f1; // Gives 10
float f2 = 10.897;
int i2 = (int) f2; // Also gives 10
You can do :
double d = 100.675;
System.out.println((int) d);
this gives you 100
.
System.out.println(Math.round(d));
gives you 101
.
You can also use :
new java.text.DecimalFormat("#").format(10.0); // => "10"
now the choice is yours that how you want to do and main thing depend on that what is your expected output is.