How to remove decimal from string

  • Thread starter Thread starter nomad
  • Start date Start date
N

nomad

Hi,

I was wondering how I would be able to remove a decimal point from a
string value i.e. 10000.0 to 10000.

Appreciate any help on this.
 
nomad explained on 21-8-2008 :
Hi,

I was wondering how I would be able to remove a decimal point from a
string value i.e. 10000.0 to 10000.

Appreciate any help on this.

You don't just want to remove a decimal point, you also want to remove
everything following that (else "10.00" would become "1000")

string s = "1000.0";
s = s.Substring(0, s.IndexOf('.', 0));

This will fail if there is no '.', so check for it (IndexOf will then
return -1).
Are you sure you will get a decimal *point*? Some countries use a
decimal comma!

Hans Kesting
 
nomad explained on 21-8-2008 :




You don't just want to remove a decimal point, you also want to remove
everything following that (else "10.00" would become "1000")

                string s = "1000.0";
                s = s.Substring(0, s.IndexOf('.', 0));

This will fail if there is no '.', so check for it (IndexOf will then
return -1).
Are you sure you will get a decimal *point*? Some countries use a
decimal comma!

Hans Kesting

Hi Hans,

Yeah, I am sure there will be a decimal point so that is exactly what
I was after. Thank you very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top