How to find No. of Digits in a number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajamohammed
    New Member
    • Jul 2007
    • 11

    How to find No. of Digits in a number

    Hi every one,
    Please tell me How to find No. of Digits in a number using java program?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by rajamohammed
    Hi every one,
    Please tell me How to find No. of Digits in a number using java program?
    Just count them; you can either do that numerically (divide by ten all the time)
    or make a string out of that number and check the string length. These tips
    should be enough for you to cook up a nice little method that does the job.

    kind regards,

    Jos

    Comment

    • rajamohammed
      New Member
      • Jul 2007
      • 11

      #3
      Originally posted by JosAH
      Just count them; you can either do that numerically (divide by ten all the time)
      or make a string out of that number and check the string length. These tips
      should be enough for you to cook up a nice little method that does the job.

      kind regards,

      Jos

      Hi,

      Thanks a lot. I used the (String.valueOf (num)).length() . Its working.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by rajamohammed
        Hi,

        Thanks a lot. I used the (String.valueOf (num)).length() . Its working.
        Watch out for negative numbers though.

        kind regards,

        Jos

        Comment

        Working...