7 Replies - 354 Views - Last Post: 05 October 2012 - 09:43 PM Rate Topic: -----

#1 exfoxs28  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-August 12

how to know how many digits

Posted 05 October 2012 - 04:49 PM

I input 2 numbers and add it ..
my problem is how to know how many digits of number is in the sum??
Is This A Good Question/Topic? 0
  • +

Replies To: how to know how many digits

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3467
  • View blog
  • Posts: 10,687
  • Joined: 05-May 12

Re: how to know how many digits

Posted 05 October 2012 - 04:51 PM

What have you tried so far?

Are the numbers integers, or are they floating point numbers, or are they complex numbers?

And do you have to follow any scientific or accounting conventions like if you add "1.75" and "0.25", the answer should be written as "2.00" and not just "2".

This post has been edited by Skydiver: 05 October 2012 - 04:53 PM

Was This Post Helpful? 0
  • +
  • -

#3 exfoxs28  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-August 12

Re: how to know how many digits

Posted 05 October 2012 - 04:53 PM

the numbers is integers...
sorry but i havent try it yet..
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3467
  • View blog
  • Posts: 10,687
  • Joined: 05-May 12

Re: how to know how many digits

Posted 05 October 2012 - 04:59 PM

Do you have to know the exact number of digits, or is a rough estimate of the minimum and maximum number of digits good enough?

Or phrased another way: are you allowed to add the two numbers first and determine the number of digits, or do you have to know the number of digits of the result without actually performing the addition?

And last question, we are talking about decimal digits, right? Not binary digits, or hexadecimal digits.
Was This Post Helpful? 0
  • +
  • -

#5 exfoxs28  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-August 12

Re: how to know how many digits

Posted 05 October 2012 - 05:04 PM

i have to know the exact number of digits

yup add the number first then determine the number of digits

yes were talking about decimal digits..
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3467
  • View blog
  • Posts: 10,687
  • Joined: 05-May 12

Re: how to know how many digits

Posted 05 October 2012 - 06:44 PM

So you said that you haven't tried anything yet. Can you describe how you would approach this problem if you had to do it with pen and paper?
Was This Post Helpful? 0
  • +
  • -

#7 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1311
  • View blog
  • Posts: 4,503
  • Joined: 19-February 09

Re: how to know how many digits

Posted 05 October 2012 - 08:26 PM

One method is to repeatedly divide the number by 10 until it reaches 0 and count the number of divide operations. Another is to convert to a string and check the length.
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3467
  • View blog
  • Posts: 10,687
  • Joined: 05-May 12

Re: how to know how many digits

Posted 05 October 2012 - 09:43 PM

Or convert to string using sprintf() and let sprintf() do the counting for you. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1