I input 2 numbers and add it ..
my problem is how to know how many digits of number is in the sum??
how to know how many digits
Page 1 of 17 Replies  611 Views  Last Post: 05 October 2012  09:43 PM
Replies To: how to know how many digits
#2
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".
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
#3
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..
sorry but i havent try it yet..
#4
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.
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.
#5
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..
yup add the number first then determine the number of digits
yes were talking about decimal digits..
#6
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?
#7
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.
#8
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.
Page 1 of 1
