-1

I need to get a float value based on percentage.

For example:

1%: 0.01 10%: 0.10 25%: 0.25 50%: 0.5 And so on.

I've tried getting a 0-100 percent value(Which works) and uploading it to a string:

String value = "0." + percent;

and parsing it as a float:

Float.parseFloat(value);

But that doesn't work. Any help is appreciated, thanks!

JediBurrell
  • 1,069
  • 10
  • 24

2 Answers2

2

float percentage = (float)intPersentValue/100.0f; this will give floating value like 25 to 0.25

AMD
  • 1,662
  • 18
  • 39
0

I did not actually get the question but are you trying to get

0.1 => 1.0 
0.015 => 0.1

or

0.1  => 100% 
0.01 => 10%

If you want 5/10 => 0.5 you can use:

int a = 5;
int b = 10;
float percentage = (float)a/float(b);

If you can elaborate a bit more I can help.

Hakes
  • 631
  • 3
  • 13