How to remove decimal from string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nomad

    How to remove decimal from string

    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.
  • Hans Kesting

    #2
    Re: How to remove decimal from string

    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


    Comment

    • nomad

      #3
      Re: How to remove decimal from string

      On Aug 21, 9:41 am, Hans Kesting <news.han...@sp amgourmet.comwr ote:
      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
      Hi Hans,

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

      Comment

      Working...