urgent : count of digits in a number

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i need a function or a macro that calculates the count of digits in a number
 
Like....

Function CountDigits(ByVal Number as integer) as integer
CountDigits = Len(Number)
End Function

Or did I miss something?

Die_Another_Day
 
If your number is in A1, then:

=LEN(A1)-IF(ISERROR(FIND(".",A1,1)>0),0,1)

This checks for a decimal point and adjusts accordingly. If the cell
will always contain a whole number, just use:

=LEN(A1)
 
=LEN(A1)
This includes any decimal separator. It also counts a single zero if the value is <1.

--
Kind regards,

Niek Otten


|i need a function or a macro that calculates the count of digits in a number
|
|
 
This function calculates the length of a number:

Function NLength(ByVal MyNum As Double) As Integer
Select Case Sgn(MyNum)
Case Is = 1
NLength = 1 + Int(Log(MyNum) / Log(10))
Case Is = 0
NLength = 1
Case Is = -1
NLength = 2 + Int(Log(Abs(MyNum)) / Log(10))
End Select
End Function

HOWEVER, this omits the fractional part: if you know the precision to which
you want to show the number, add 1 + the number of digits after the decimal
point to the result.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top