signfiicant figures

G

Guest

I have two tables, one with two fields, the second also with two fields with
one of fields being identical to the first

one field is a text field the second is an integer field

I wish to create a query that retrieves that retrieves the text field from
the second table as well as teh number value of the second field in that
record. I then wish to round the value of this second field to the number
of significant figures as defined by the first table, second field....HOW?????

example

Table 1
---------

XYZ 2
XSC 3

Table 2
--------

XYZ 3.432
XSC 1043.4

the query shoudl return
XYZ being 3.4 (2 signficant figures) and
XSC being 1040 (3 significant figures)
 
G

Guest

Since the syntax for the Round function is Round (BaseNumber,
SignificantDigits), just try this:

Let's call the text field Key in both tables, the base number in Table1
Base, and the significant digits in Table2 SigDigits.

Join the tables on the Key (text field), then use:
Round([Base],[SigDigits]). Here is the full SQL:

SELECT Table1.Key, Round([Base],[SigDigits]) AS Result
FROM Table1 INNER JOIN Table2 ON Table1.Key = Table2.Key;
 
G

Guest

unfortunately round is the number of digits after the decimal point. not
significant figures
--
Regards


Patrick Stubbin


Brian said:
Since the syntax for the Round function is Round (BaseNumber,
SignificantDigits), just try this:

Let's call the text field Key in both tables, the base number in Table1
Base, and the significant digits in Table2 SigDigits.

Join the tables on the Key (text field), then use:
Round([Base],[SigDigits]). Here is the full SQL:

SELECT Table1.Key, Round([Base],[SigDigits]) AS Result
FROM Table1 INNER JOIN Table2 ON Table1.Key = Table2.Key;

Patrick Stubbin said:
I have two tables, one with two fields, the second also with two fields with
one of fields being identical to the first

one field is a text field the second is an integer field

I wish to create a query that retrieves that retrieves the text field from
the second table as well as teh number value of the second field in that
record. I then wish to round the value of this second field to the number
of significant figures as defined by the first table, second field....HOW?????

example

Table 1
---------

XYZ 2
XSC 3

Table 2
--------

XYZ 3.432
XSC 1043.4

the query shoudl return
XYZ being 3.4 (2 signficant figures) and
XSC being 1040 (3 significant figures)

--
Regards


Patrick Stubbin
 
G

Guest

Sorry...my error. It's been a looooong time since I had to think about
significant digits. I have a partial answer, but correct me if it is not
complete. Let's see - if the number is less than 1, then decimal place
rounding works, but if it is more than 1, we need to do something a little
fancier. Basically, we need to move over the required number of digits so we
can use the Round function, which works only with decimal place, then move
the decimal point back over again.

Create a new module, then paste the function below into it. Then, in your
query, you can just use Result(Base,SigDig). You can use the JOIN in my
original post to link the Base & SigDig figures.

The only (I think) thing this does not do is show the trailing zeros when
they are, indeed significant. If my memory serves me correctly, 123.001 to 4
significant digits is 123.0, not just 123. If I am correct, then it would
take a little work with a Format function to get those to display.

Function Result(Base As Double, SigDig As Integer) As Double
If Base > 1 Then
Dim Calc1 As Long
Dim Calc2 As Long
Dim Calc3 As Double
Dim Calc4 As Double
Calc1 = Int(Base)
Calc2 = Len(Str(Calc1) - 1)
Calc3 = Base / (10 ^ Calc2)
Calc4 = Round(Calc3, SigDig)
Result = Calc4 * 10 ^ Calc2
Else
Result = Round(Base, SigDig)
End If
End Function

I know it's a lot of manipulation, but it first moves the decimal place over
to make the number less than 1 (by counting the number of digits in the
integer part of the number), then it rounds that result to the number of
significant digits, then it moves the decimal place back over.

With my luck, there is probably already a native Access function for
this...but I couldn't find it.

Patrick Stubbin said:
unfortunately round is the number of digits after the decimal point. not
significant figures
--
Regards


Patrick Stubbin


Brian said:
Since the syntax for the Round function is Round (BaseNumber,
SignificantDigits), just try this:

Let's call the text field Key in both tables, the base number in Table1
Base, and the significant digits in Table2 SigDigits.

Join the tables on the Key (text field), then use:
Round([Base],[SigDigits]). Here is the full SQL:

SELECT Table1.Key, Round([Base],[SigDigits]) AS Result
FROM Table1 INNER JOIN Table2 ON Table1.Key = Table2.Key;

Patrick Stubbin said:
I have two tables, one with two fields, the second also with two fields with
one of fields being identical to the first

one field is a text field the second is an integer field

I wish to create a query that retrieves that retrieves the text field from
the second table as well as teh number value of the second field in that
record. I then wish to round the value of this second field to the number
of significant figures as defined by the first table, second field....HOW?????

example

Table 1
---------

XYZ 2
XSC 3

Table 2
--------

XYZ 3.432
XSC 1043.4

the query shoudl return
XYZ being 3.4 (2 signficant figures) and
XSC being 1040 (3 significant figures)

--
Regards


Patrick Stubbin
 

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

Top