Reputation: 271
I understand how to delete part of a string from following this example
But the problem is my string is constantly changing.
str is giving back a value of: 80.30000 this changes depending on the value selected. What I'm trying to is remove all of the characters after the . so it should look like this.
str = 80
the string value is currently stored in str '80.30000'
Any suggestions ?
Upvotes: 0
Views: 51
Reputation: 144
The best answer has probably already been given, but if you're using the number for anything mathematical, an alternativel might be to cast the String to a Float, Math.floor() the float (which should give you an integer), then cast it back to a String if required.
Upvotes: 0
Reputation:
Strings have functions like indexOf. So, in order to get the position of the character .
you can do the following.
var str:String = "80.30000";
var indexOfPoint:int = str.indexOf(".");
if(indexOfPoint >= 0)
{
//the string contains at least one . character
str = str.substring(0, indexOfPoint);
//now str holds only the String "80"
}
Documentation for substring(int,int)
Upvotes: 2