?
Solved

How to mathematically find out how many digits a number contain?

Posted on 2006-10-25
10
Medium Priority
?
324 Views
Last Modified: 2008-02-01
Hello. I have another question. How to mathematically find out how many digits a number contain?
0
Comment
Question by:m-jansen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17805796
floor(log(number)/log(10))
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17805805
Hi m-jansen,

Keep dividing the number by increasing powers of 10 until you get quotient 0

div = 10
count =1
while (num/div)
{
     div = div * 10
     count = count +1
}

Cheers!
sunnycoder
0
 
LVL 84

Accepted Solution

by:
ozo earned 750 total points
ID: 17805831
floor(1+log(floor(number)+.9)/log(10))
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:m-jansen
ID: 17805960
looks like
floor(1+log(number))
gave me the number of digits too... is that right?
0
 
LVL 39

Expert Comment

by:Adam314
ID: 17806206
If your log function assumes base 10.  The /log(10) takes care of when log doesn't use base 10.
0
 
LVL 22

Expert Comment

by:grg99
ID: 17806755
I guess it depends how accurate you need the answer to be, and the consequences of a possible off-by-one or two or three or six error.

Also you may not really want this.  For example,  this is the wrong way to calculate how much space you'll need to store the number as text.

If you could explain what you're trying to do maybe we can come up with the best answer.

0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 17806885
Negative numbers.
Decimals.
0
 

Author Comment

by:m-jansen
ID: 17806931
I am trying to get the length of an integer in VHDL.
0
 

Author Comment

by:m-jansen
ID: 17806943
...the number of digits in an VHDL integer
0
 

Author Comment

by:m-jansen
ID: 17807601
I think ozo answer is good enough. Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Complex Numbers are funny things.  Many people have a basic understanding of them, some a more advanced.  The confusion usually arises when that pesky i (or j for Electrical Engineers) appears and understanding the meaning of a square root of a nega…
This article seeks to propel the full implementation of geothermal power plants in Mexico as a renewable energy source.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question