I've got a series of float numbers; I want to display them as they are;
but while I use String.getValueOf
.0 will be added to my numbers
ie 10 is shows as 10.0
what should i do to prevent this mess ?
Asked
Active
Viewed 1,993 times
0

Shervin4030
- 27
- 1
- 9
-
Don't use a float if you don't want the decimal place – takendarkk Dec 23 '13 at 17:39
3 Answers
2
Try
if(stringVariable.endsWith(".0")) stringVariable = stringVariable.replace(".0" , "");
This way it will remove .0 only if the string ends with .0
Hope this helps.

anestv
- 543
- 6
- 28
-
I get this Error : The method endsWith(String) in the type String is not applicable for the arguments (double) – Shervin4030 Dec 23 '13 at 17:46
-
0
using something like sprintf would do it
String.format("%.0f", value);

0xFADE
- 832
- 5
- 7
-
can u elaborate this with an example ; let say we have 5.65656565 in an array. – Shervin4030 Dec 23 '13 at 18:02
-
%.0f means display a float with nothing after the . You could say %.2f if you wanted to show 2 decimal places for example. – 0xFADE Dec 23 '13 at 18:06
-
what if I dont know that my string is 0 or 0.121212 ; applying this doesnt give me 0.00 ? – Shervin4030 Dec 23 '13 at 18:33
-
Dear 0xFADE ! can you help me on this ? when I apply what you said with the accepted answer of my question; everything is right but I get 10.00 ; how do i remove those 00 ? – Shervin4030 Dec 23 '13 at 18:50
-