1

I'm trying to convert an Integer to a Float since I need to use some math and need the decimals offered by floats.

public static Float currAccu() {
float accuMiss, accuHit, accuCrit;

accuMiss = Float.parseFloat(publicInt.returnMissCount());
accuHit = Float.parseFloat(publicInt.returnHitCount());
accuCrit = Float.parseFloat(publicInt.returnMissCount());

return 0;

The code is incomplete and I'm pretty new at Java. I've used to the Float.parseFloat to convert string to float before. The return will be different, but until I get the conversion working I will continue to fix it.

Mike G
  • 4,232
  • 9
  • 40
  • 66
PXS
  • 33
  • 1
  • 5
  • 1
    possible duplicate of [How can I convert integer into float in Java?](http://stackoverflow.com/questions/4377842/how-can-i-convert-integer-into-float-in-java) – Mike G Dec 04 '14 at 17:19
  • Question: Do you want a `float` or a `Float`? And is your "integer" in String form or is it an `int`? – Hot Licks Dec 04 '14 at 17:25
  • I did actually look at that post, didn't quite understand it though. – PXS Dec 04 '14 at 17:58

1 Answers1

2

CASTING IS THE SOLUTION

 int b;
 float n = (float) b ;

in your case

float  accuMiss = (float)(publicInt.returnMissCount());
mehari
  • 3,057
  • 2
  • 22
  • 34