PC Review


Reply
Thread Tools Rate Thread

3 most significant digits

 
 
Gaba
Guest
Posts: n/a
 
      19th Oct 2009
Hi there,
I'm using the following code to get the 3 most significant numbers on a
cell. The cell properties is set to General
------------------------------------------------------------------------------------
For Each c In Range("F9", "F25")
c.Offset(0, 3).Value = Application.Round(c.Value, 2 - Int(Log10(c.Value)))
nex
...........................................................................................................
Static Function Log10(x)
Log10 = Log(x) / Log(10#)
End Functio
---------------------------------------------------------------------------------------
it works except when the value is 0.30 it shows 0.3
How can I set the properties or change the code so it shows always the 3
most significant digits?
0.3215 0.322
0.3000 0.300
80.84 80.8
530.15 530
and so on

Any help is appreciated.
Gaba
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      19th Oct 2009
Your code does not *get* the 3 most significant digits... it *rounds* your
number to 3 significant digits. Since your cell's format is set to General,
numbers are displayed as numbers... and numbers do not have trailing zeroes.
The only way you will be able to display the trailing zeroes is by changing
the cell's format to Text or to modify the code to have it change the cell's
format on the fly to a custom format that displays your 3 significant
figures. If you would like the latter, post back showing us your actual code
(copy/paste it into your message, don't try to retype it). By the way, will
it ever be possible for your numbers to be in e-notation (such as 1.2345e67)
and, if so, would you want the number in front of the "e" to be rounded to 3
significant digits?

--
Rick (MVP - Excel)


"Gaba" <(E-Mail Removed)> wrote in message
news:AF4EED61-21E9-4678-8430-(E-Mail Removed)...
> Hi there,
> I'm using the following code to get the 3 most significant numbers on a
> cell. The cell properties is set to General
> ------------------------------------------------------------------------------------
> For Each c In Range("F9", "F25")
> c.Offset(0, 3).Value = Application.Round(c.Value, 2 -
> Int(Log10(c.Value)))
> next
> ..........................................................................................................
> Static Function Log10(x)
> Log10 = Log(x) / Log(10#)
> End Function
> ---------------------------------------------------------------------------------------
> it works except when the value is 0.30 it shows 0.3
> How can I set the properties or change the code so it shows always the 3
> most significant digits?
> 0.3215 0.322
> 0.3000 0.300
> 80.84 80.8
> 530.15 530
> and so on
>
> Any help is appreciated.
> Gaba


 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      19th Oct 2009
Hi Gaba,

You can either manually set the number format of the cells on the worksheet
or with code you can set the number format of the cell as follows:-

Tthe following code will format the entire range.
Range("F9", "F25").Offset(0, 3).NumberFormat = "0.000"

The following code will format each cell individually after the result is
assigned to it.
For Each c In Range("F9", "F25")
c.Offset(0, 3).Value = Application.Round(c.Value, 2 - Int(Log10(c.Value)))
c.Offset(0, 3).NumberFormat = "0.000"
Next


--
Regards,

OssieMac


 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      19th Oct 2009
Hi again Gaba,

I think that you might need to precede log10 with worksheetfunction also.

WorksheetFunction.Log10

--
Regards,

OssieMac


 
Reply With Quote
 
Bernd P
Guest
Posts: n/a
 
      19th Oct 2009
Hello,

Leading or trailing zeros are no significant digits.

A correct and efficient solution you can find here:
http://sulprobil.com/html/nsig.html

Regards,
Bernd
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Significant digits Andy Microsoft Access 1 7th Jun 2009 12:42 AM
significant digits Gordon Microsoft Excel Worksheet Functions 20 1st Oct 2008 07:14 PM
Significant Digits =?Utf-8?B?TGFycnkgRy4=?= Microsoft Access 6 28th Dec 2005 08:25 PM
Significant digits =?Utf-8?B?TWFyY3Vz?= Microsoft Excel Worksheet Functions 5 16th Nov 2005 03:39 PM
Significant Digits BuddyWork Microsoft C# .NET 1 30th Jul 2004 10:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:31 PM.