Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. count decimal point

count decimal point

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    webhay
    wrote on last edited by
    #1

    Hello all, How can i count the nuber after the decimal point. Please Help Thanks Hoho

    N R M 3 Replies Last reply
    0
    • W webhay

      Hello all, How can i count the nuber after the decimal point. Please Help Thanks Hoho

      N Offline
      N Offline
      NetRocker
      wrote on last edited by
      #2

      Can you provide more information? I did not understand what you meant by count the number!!

      W 1 Reply Last reply
      0
      • W webhay

        Hello all, How can i count the nuber after the decimal point. Please Help Thanks Hoho

        R Offline
        R Offline
        Roy Heil
        wrote on last edited by
        #3

        Very tricky. The problem is in the datatype you use to represent the number. Floating points don't accuratly represent the number they are supposed to. It could be off by a very small amount. Thus, if you have a number like 17.2, the internal representation may be 17.1999999. Your may want 1, because 17.2 is the real value, or you may want infinity, because the real value repeats for ever. How important is it that you can do this? Roy.

        1 Reply Last reply
        0
        • N NetRocker

          Can you provide more information? I did not understand what you meant by count the number!!

          W Offline
          W Offline
          webhay
          wrote on last edited by
          #4

          Thanks for your reply I need to count how many numbers after the decimal point for instance if 3.44 or 3.4 i need to count how many number after the decimal point it is now two number in the frist number and one number in the frist number. Thanks for your time Best regards, Hoho

          1 Reply Last reply
          0
          • W webhay

            Hello all, How can i count the nuber after the decimal point. Please Help Thanks Hoho

            M Offline
            M Offline
            mav northwind
            wrote on last edited by
            #5

            Hello! One thing that comes to mind is to convert the number to a string and then search for the decimal separator:

            int FractionDigits(double d)
            {
            string s = d.ToString();
            int i = s.IndexOf(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            if (i<0)
            return 0;
            else
            return s.Length-i-1;
            }

            The maximum number you'll get depends on how double.ToString() formats your number. Usually you'll get up to 15 digits, but that's enough for most practical cases. Regards, mav

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups