我需要根据百分比获得浮动值。
例如:
1%: 0.01
10%: 0.10
25%: 0.25
50%: 0.5
等等。
我尝试获得0-100%的价值(哪个有效)并将其上传到字符串中:
String value = "0." + percent;
并将其解析为float:
Float.parseFloat(value);
但这并不奏效。 感谢任何帮助,谢谢!
答案 0 :(得分:1)
float percentage =(float)intPersentValue / 100.0f; 这将给出浮动值,如25到0.25
答案 1 :(得分:0)
我实际上没有得到问题但是你想要
0.1 => 1.0
0.015 => 0.1
或
0.1 => 100%
0.01 => 10%
如果你想要5/10 => 0.5你可以使用:
int a = 5;
int b = 10;
float percentage = (float)a/float(b);
如果你能详细说明一下,我可以提供帮助。