Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 136
Default Round Function (Significant Figures) for Large Numbers

Hi Rob,

First my formula suggestion: =--TEXT(A1,"0."&REPT("0",A2-1)&"E+000")
In A1 you have your original number, in A2 the count of significant
digits you want.

My UDF:
Function dbl2nsig(d As Double, _
Optional n As Long = 3) _
As String
'Returns string presentation of d with
'n significant digits. PB V0.01
Dim i As Long, j As Long
Dim s As String, sr As String
s = Format(d, "0." & String(n - 1, "0") _
& "E+000")
i = Right(s, 4)
Select Case i
Case Is n - 2
sr = Left(s, 1)
If n 1 Then sr = sr & Mid(s, 3, n - 1)
sr = sr & String(i - n + 1, "0")
Case 0
sr = Left(s, n + 1)
Case Is < 0
sr = "0." & String(-1 - i, "0") & Left(s, 1) _
& Mid(s, 3, n - 1)
Case Else
s = Left(s, 1) & Mid(s, 3, n - 1)
sr = Left(s, i + 1) & "." & _
Right(s, n - i - 1)
End Select
dbl2nsig = sr
End Function

HTH,
Bernd

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
significant figures Crystal Excel Worksheet Functions 14 July 8th 09 07:36 PM
significant figures? bgarey Excel Discussion (Misc queries) 15 September 3rd 08 08:01 PM
Rounding/Significant figures cloots Excel Worksheet Functions 5 September 1st 05 04:03 PM
more newbie help on my significant figures function... James Bond Excel Programming 7 August 31st 04 04:18 PM
pls help newbie with my significant figures function James Bond Excel Programming 5 August 29th 04 11:57 PM


All times are GMT +1. The time now is 06:55 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"