Solved

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

Posted on 2006-10-25
10
317 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
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 250 total points
ID: 17805831
floor(1+log(floor(number)+.9)/log(10))
0
Independent Software Vendors: 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!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Group Data Frequency Distribution 9 51
Relative Frequency Assessment 2 38
Triangle - computing angles 3 61
Simple Calculation for Value of Availablity 5 97
This article seeks to propel the full implementation of geothermal power plants in Mexico as a renewable energy source.
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
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…

679 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