To trim a string value

Hi!

I have a string value that can look somewhat like this:
"410.13456"
"1024.7940"
or something like that.

What I want to do is, if there's a "." in the string, remove everything behind it. Ie. "410.13456" will become "410".

How do I do this the simplest way possible.

Regards,
David
larsanAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
objectsConnect With a Mentor Commented:
int dot = s.indexOf(".");
if (dot!=-1)
{
   s = s.substring(0, dot-1);
}
0
 
objectsCommented:
or maybe:

s = s.split("\.")[0];
0
 
larsanAuthor Commented:
The first one works if you put it like this:

s=s.substring(0,dot);

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.