Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default urgent : count of digits in a number

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default urgent : 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default urgent : count of digits in a number

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)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default urgent : count of digits in a number

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

--
Kind regards,

Niek Otten


"SHIRA" wrote in message ...
|i need a function or a macro that calculates the count of digits in a number
|
|


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default urgent : 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.


"SHIRA" wrote:

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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count number of digits in a cell Julieeeee Excel Worksheet Functions 7 April 3rd 23 04:19 PM
VBA write macro change column with 3 number digits to 4 digits the James C[_2_] Excel Discussion (Misc queries) 3 January 25th 10 03:12 PM
number 12 digits to 15 digits mehdy-e Excel Discussion (Misc queries) 5 November 13th 09 04:43 PM
Count number of digits (Numbers) JohnUK Excel Discussion (Misc queries) 3 November 28th 08 05:08 PM
How to customize number to 10 digits including 2 digits after deci Carina Excel Worksheet Functions 3 September 20th 07 02:50 AM


All times are GMT +1. The time now is 10:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"