-1

I want to change a float coming from server to string or string to float. Can i convert string to float coming from server?

    String coming;
    coming = new String(rec.getData());
        Toast.makeText(getApplicationContext(),comnig,Toast.LENGTH_LONG).show();
Pankaj
  • 7,908
  • 6
  • 42
  • 65
Saeedr
  • 19
  • 5

2 Answers2

1

Yes you can convert a String to a float. Simply do:

Float.parseFloat(string);

You may want to surround this with a try and catch because if the string is not compatible with type float it will create a stack-trace.

Forseth11
  • 1,418
  • 1
  • 12
  • 21
0

check this out https://stackoverflow.com/a/7552675/2329972

converting string to float

float f = Float.parseFloat(coming);

it's better to use try -catch , because your coming value may contain something that are not compatible with float type .

Community
  • 1
  • 1
Soroush
  • 116
  • 7