dbTalk Databases Forums  

Re: Significant digits - any ideas ?

comp.databases.filemaker comp.databases.filemaker


Discuss Re: Significant digits - any ideas ? in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Christoph Bouthillier
 
Posts: n/a

Default Re: Significant digits - any ideas ? - 08-06-2003 , 10:59 AM






Hello Peter

First an important warning: At least in FMP v 4.0 the Round function is
totally buggy. Never use it! See www.tekstotaal.com/c.fmp.truncate.bug.html

I read some contradiction in your question: You write that trailing zeroes
are not signficant and later on you say that they are indeed significant.

As the the core question: Why not multiply by e.g. 1000000000, cut/round
everything behind the first 4 digits and the divide again by 1000000000 ? Or
am I mistaken here

--


Met vriendelijke groet / Mit freundlichen Grüßen / With kind regards
Christoph Bouthillier
post (-a-t-) no-no-spam tekstotaal dot com
Please remove "no-no-spam" when e-mailing me directly - Thanks
------
"Peter" <nomail (AT) homeorwork (DOT) tnx> schreef in bericht
news:bgr2g3$89f$1 (AT) reader08 (DOT) wxs.nl...
Quote:
Hi all,

I need a calculated result to be rounded in 4 significant digits. Just to
make it clear, significant digits are any digits excluding leading zeroes.
E.g. in 0.0045717 the first significant digit is 4 and my desired result
would be 0.004572.

The solution I found was the following :

Position_calc:

Min(
Case(Position(field; 1 ; 1 ; 1 )=0;30;Position(field; 1 ; 1 ; 1 ));
Case(Position(field; 2 ; 1 ; 1 )=0;30;Position(field; 2 ; 1 ; 1 ));

// and so on up to

Case(Position(field; 9 ; 1 ; 1 )=0;30;Position(field ; 9 ; 1 ; 1 ))
)

This checks the number for the first significant digit (1-9). Because the
absence of any of the digits 1-9 will return a 0-value I check for this
with
the Case-statements and, if the value is 0, set it to 30 (arbitrary
number,
just to prevent getting a 0-result).

Then, to round the field correctly, I use another calculation :
Round(field;Position_calc + 2)

It works OK, but I would like to know if there is another/easier/faster
way
to do this. Secondly, this doesn't work if the last significant digit is a
"0" because Filemaker just discards any trailing zeroes, although they are
significant.

Thanks,

Peter





Reply With Quote
  #2  
Old   
Peter
 
Posts: n/a

Default Re: Significant digits - any ideas ? - 08-06-2003 , 12:57 PM






Hi Christoph,

thanks for answering and pointing out the Round-bug. I'm using V5 so I hope
its behaviour has improved.

As to the seeming contradiction: I initially indicated that *leading*
zeroes (0 before the first non-zero digit) were insignificant, but
*trailing* zeroes (zero after the 3rd non-zero digit) were not.

I'm afraid your suggestion of multiplying/dividing would not work. Just a
simple test :

0.045678945 * 10000000000 = 456789450
4567/10000000000 = 0.0000004567

Thanks again,

Peter

On Wed, 6 Aug 2003 17:59:24 +0200, Christoph Bouthillier wrote:

Quote:
Hello Peter

First an important warning: At least in FMP v 4.0 the Round function is
totally buggy. Never use it! See www.tekstotaal.com/c.fmp.truncate.bug.html

I read some contradiction in your question: You write that trailing zeroes
are not signficant and later on you say that they are indeed significant.

As the the core question: Why not multiply by e.g. 1000000000, cut/round
everything behind the first 4 digits and the divide again by 1000000000 ? Or
am I mistaken here

Reply With Quote
  #3  
Old   
Christoph Bouthillier
 
Posts: n/a

Default Re: Significant digits - any ideas ? - 08-06-2003 , 02:03 PM



Hello Peter,

Ah, now I finally know why I got such *bad* marks in maths at school ;=(((
I'm sorry...

--


Met vriendelijke groet / Mit freundlichen Grüßen / With kind regards
Christoph Bouthillier
post (-a-t-) no-no-spam tekstotaal dot com
Please remove "no-no-spam" when e-mailing me directly - Thanks
------
"Peter" <nomail (AT) homeorwork (DOT) tnx> schreef in bericht
news:1ur9hqu2m00xp$.19faj1uz6s762.dlg (AT) 40tude (DOT) net...
Quote:
Hi Christoph,

thanks for answering and pointing out the Round-bug. I'm using V5 so I
hope
its behaviour has improved.

As to the seeming contradiction: I initially indicated that *leading*
zeroes (0 before the first non-zero digit) were insignificant, but
*trailing* zeroes (zero after the 3rd non-zero digit) were not.

I'm afraid your suggestion of multiplying/dividing would not work. Just a
simple test :

0.045678945 * 10000000000 = 456789450
4567/10000000000 = 0.0000004567

Thanks again,

Peter

On Wed, 6 Aug 2003 17:59:24 +0200, Christoph Bouthillier wrote:

Hello Peter

First an important warning: At least in FMP v 4.0 the Round function is
totally buggy. Never use it! See
www.tekstotaal.com/c.fmp.truncate.bug.html

I read some contradiction in your question: You write that trailing
zeroes
are not signficant and later on you say that they are indeed
significant.

As the the core question: Why not multiply by e.g. 1000000000, cut/round
everything behind the first 4 digits and the divide again by 1000000000
? Or
am I mistaken here



Reply With Quote
  #4  
Old   
Peter
 
Posts: n/a

Default Re: Significant digits - any ideas ? - 08-07-2003 , 10:09 AM



Hi Glenn,

I sure hope you had this one lying around somewhere and didn't have to
invent it from scratch ;-)

It works like a charm, but I'm not sure it's any simpler than what I had
done (although it's very nice that you can set the number of significant
digits !). I haven't gotten around to look at the math of it all since I'm
frantically trying to clear my desk before I'm off for a two week holiday.

Thanks again,

Peter


Quote:
Assuming fields:

Number (number)

SignificantDigits (number)

Calculation (calculation, number) =

Int( (Number * (10 ^ ((Position( Number, Left( Substitute( Substitute(
Number, ".", ""), "0", ""), 1), 1, 1)) - (Case( PatternCount( Number,
"."),
Position( Number, ".", 1, 1), Length( Number) + 1)) + SignificantDigits -
((Position( Number, Left( Substitute( Substitute( Number, ".", ""), "0",
""), 1), 1, 1)) > (Case( PatternCount( Number, "."), Position( Number,
".",
1, 1), Length( Number) + 1)))))) + .5) / (10 ^ ((Position( Number, Left(
Substitute( Substitute( Number, ".", ""), "0", ""), 1), 1, 1)) - (Case(
PatternCount( Number, "."), Position( Number, ".", 1, 1), Length( Number)
+
1)) + SignificantDigits - ((Position( Number, Left( Substitute(
Substitute( Number, ".", ""), "0", ""), 1), 1, 1)) > (Case( PatternCount(
Number, "."), Position( Number, ".", 1, 1), Length( Number) + 1)))))


"Peter" <nomail (AT) homeorwork (DOT) tnx> wrote in message
news:bgr2g3$89f$1 (AT) reader08 (DOT) wxs.nl...
Hi all,

I need a calculated result to be rounded in 4 significant digits. Just
to
make it clear, significant digits are any digits excluding leading
zeroes.
E.g. in 0.0045717 the first significant digit is 4 and my desired result
would be 0.004572.

The solution I found was the following :

Position_calc:

Min(
Case(Position(field; 1 ; 1 ; 1 )=0;30;Position(field; 1 ; 1 ; 1 ));
Case(Position(field; 2 ; 1 ; 1 )=0;30;Position(field; 2 ; 1 ; 1 ));

// and so on up to

Case(Position(field; 9 ; 1 ; 1 )=0;30;Position(field ; 9 ; 1 ; 1 ))
)

This checks the number for the first significant digit (1-9). Because
the
absence of any of the digits 1-9 will return a 0-value I check for this
with
the Case-statements and, if the value is 0, set it to 30 (arbitrary
number,
just to prevent getting a 0-result).

Then, to round the field correctly, I use another calculation :
Round(field;Position_calc + 2)

It works OK, but I would like to know if there is another/easier/faster
way
to do this. Secondly, this doesn't work if the last significant digit is
a
"0" because Filemaker just discards any trailing zeroes, although they
are
significant.

Thanks,

Peter







Reply With Quote
  #5  
Old   
Bridget Eley
 
Posts: n/a

Default Re: Significant digits - any ideas ? - 08-07-2003 , 09:43 PM



Hi Peter

Here is my offering:

Left(Number, Position(Number, ".", 1, 1) - 1) & Round("." &
TextToNum(Right(Number, Length(Number) - Position(Number, ".", 1,
1))),SignificantDigits)
/
TextToNum(Left("10000000000000000000", Length(Right(Number, 1 +
Length(Number) - Position(Number, ".", 1, 1))) -
Length(NumToText(TextToNum(Right(Number, Length(Number) - Position(Number,
".", 1, 1)))))))

I tackled it predominantly as a text problem. I began by using the right
function to grab everything after the decimal point (=X). Then I converted
the text to a number to lose the leading zeroes (=Y), then rounded the
result using Glenn's SignificantDigits field as the number parameter (=Z).
Then, to reinsert the leading zeroes, I divided Z by a figure that I
obtained using Left to extract characters to the value of the difference
between the length of X and the length of Y (which = the number of leading
zeroes) plus 1 from "100000000000000000000000". Finally, I added anything
that happened to be before the decimal place in the event that number is
greater than one or in the negative range. You don't say whether the calc
needs to be able to do this. NB: I have given the text parameter of the
Left function only 20 digits, but this could be extended theoretically to
the max no of characters that that parameter will take which is 253.

Bridget Eley



in article bgr2g3$89f$1 (AT) reader08 (DOT) wxs.nl, Peter at nomail (AT) homeorwork (DOT) tnx
wrote on 7/8/03 12:13 AM:

Quote:
Hi all,

I need a calculated result to be rounded in 4 significant digits. Just to
make it clear, significant digits are any digits excluding leading zeroes.
E.g. in 0.0045717 the first significant digit is 4 and my desired result
would be 0.004572.

The solution I found was the following :

Position_calc:

Min(
Case(Position(field; 1 ; 1 ; 1 )=0;30;Position(field; 1 ; 1 ; 1 ));
Case(Position(field; 2 ; 1 ; 1 )=0;30;Position(field; 2 ; 1 ; 1 ));

// and so on up to

Case(Position(field; 9 ; 1 ; 1 )=0;30;Position(field ; 9 ; 1 ; 1 ))
)

This checks the number for the first significant digit (1-9). Because the
absence of any of the digits 1-9 will return a 0-value I check for this with
the Case-statements and, if the value is 0, set it to 30 (arbitrary number,
just to prevent getting a 0-result).

Then, to round the field correctly, I use another calculation :
Round(field;Position_calc + 2)

It works OK, but I would like to know if there is another/easier/faster way
to do this. Secondly, this doesn't work if the last significant digit is a
"0" because Filemaker just discards any trailing zeroes, although they are
significant.

Thanks,

Peter




Reply With Quote
  #6  
Old   
Shadenfroh
 
Posts: n/a

Default Re: Significant digits - any ideas ? - 08-09-2003 , 12:06 PM



I got "hooked," too. :-)

Here's what I came up with:

Case( Mod( Number , 1 ) > 0 ,
Int( Number ) + Round( Mod( Number , 1 ) , Position( Mod( Number , 1 ) ,
Left( Substitute( Substitute( Mod( Number , 1 ) , "0" , "" ) , "." , "" ) ,
1 ) , 1 , 1 ) + 2 ) , Number ) &
Substitute( 10 ^ ( ( Length( Int( Number ) ) + Position( Mod( Number , 1 ) ,
Left( Substitute( Substitute( Mod( Number , 1 ) , "0" , "" ) , "." , "" ) ,
1 ) , 1 , 1 ) + 3 ) - Length( Case( Mod( Number , 1 ) > 0 ,
Int( Number ) + Round( Mod( Number , 1 ) , Position( Mod( Number , 1 ) ,
Left( Substitute( Substitute( Mod( Number , 1 ) , "0" , "" ) , "." , "" ) ,
1 ) , 1 , 1 ) + 2 ) , Number ) ) ) , "1" , "" )

There's some rather obvious redundancy here, which could be eliminated by
additional calc fields, but it's more fun to do it all in one calc. ;-)

--
Shadenfroh
shadenfroh (AT) yahoo (DOT) com

"Peter" <nomail (AT) homeorwork (DOT) tnx> wrote

Quote:
Hi all,

I need a calculated result to be rounded in 4 significant digits. Just to
make it clear, significant digits are any digits excluding leading zeroes.
E.g. in 0.0045717 the first significant digit is 4 and my desired result
would be 0.004572.

The solution I found was the following :

Position_calc:

Min(
Case(Position(field; 1 ; 1 ; 1 )=0;30;Position(field; 1 ; 1 ; 1 ));
Case(Position(field; 2 ; 1 ; 1 )=0;30;Position(field; 2 ; 1 ; 1 ));

// and so on up to

Case(Position(field; 9 ; 1 ; 1 )=0;30;Position(field ; 9 ; 1 ; 1 ))
)

This checks the number for the first significant digit (1-9). Because the
absence of any of the digits 1-9 will return a 0-value I check for this
with
the Case-statements and, if the value is 0, set it to 30 (arbitrary
number,
just to prevent getting a 0-result).

Then, to round the field correctly, I use another calculation :
Round(field;Position_calc + 2)

It works OK, but I would like to know if there is another/easier/faster
way
to do this. Secondly, this doesn't work if the last significant digit is a
"0" because Filemaker just discards any trailing zeroes, although they are
significant.

Thanks,

Peter






Reply With Quote
  #7  
Old   
Shadenfroh
 
Posts: n/a

Default Re: Significant digits - any ideas ? - 08-09-2003 , 12:10 PM



Your calc is graceful. However, when I tried it, I didn't get the trailing
zeros to four significant digits.

In my calc, the portion that does the same as your calc (as near as I can
tell) looks like this:

Case( Mod( Number , 1 ) > 0 ,
Int( Number ) + Round( Mod( Number , 1 ) , Position( Mod( Number , 1 ) ,
Left( Substitute( Substitute( Mod( Number , 1 ) , "0" , "" ) , "." , "" ) ,
1 ) , 1 , 1 ) + 2 ) , Number )

The rest of my calc (in the other post) is to get the right number of those
pesky zeroes on the end. :-D

--
Shadenfroh
shadenfroh (AT) yahoo (DOT) com

"Bridget Eley" <bridgeteley (AT) ihug (DOT) com.au> wrote

Quote:
Hi Peter

Here is my offering:

Left(Number, Position(Number, ".", 1, 1) - 1) & Round("." &
TextToNum(Right(Number, Length(Number) - Position(Number, ".", 1,
1))),SignificantDigits)
/
TextToNum(Left("10000000000000000000", Length(Right(Number, 1 +
Length(Number) - Position(Number, ".", 1, 1))) -
Length(NumToText(TextToNum(Right(Number, Length(Number) - Position(Number,
".", 1, 1)))))))

I tackled it predominantly as a text problem. I began by using the right
function to grab everything after the decimal point (=X). Then I
converted
the text to a number to lose the leading zeroes (=Y), then rounded the
result using Glenn's SignificantDigits field as the number parameter (=Z).
Then, to reinsert the leading zeroes, I divided Z by a figure that I
obtained using Left to extract characters to the value of the difference
between the length of X and the length of Y (which = the number of leading
zeroes) plus 1 from "100000000000000000000000". Finally, I added anything
that happened to be before the decimal place in the event that number is
greater than one or in the negative range. You don't say whether the calc
needs to be able to do this. NB: I have given the text parameter of the
Left function only 20 digits, but this could be extended theoretically to
the max no of characters that that parameter will take which is 253.

Bridget Eley



in article bgr2g3$89f$1 (AT) reader08 (DOT) wxs.nl, Peter at nomail (AT) homeorwork (DOT) tnx
wrote on 7/8/03 12:13 AM:

Hi all,

I need a calculated result to be rounded in 4 significant digits. Just
to
make it clear, significant digits are any digits excluding leading
zeroes.
E.g. in 0.0045717 the first significant digit is 4 and my desired result
would be 0.004572.

The solution I found was the following :

Position_calc:

Min(
Case(Position(field; 1 ; 1 ; 1 )=0;30;Position(field; 1 ; 1 ; 1 ));
Case(Position(field; 2 ; 1 ; 1 )=0;30;Position(field; 2 ; 1 ; 1 ));

// and so on up to

Case(Position(field; 9 ; 1 ; 1 )=0;30;Position(field ; 9 ; 1 ; 1 ))
)

This checks the number for the first significant digit (1-9). Because
the
absence of any of the digits 1-9 will return a 0-value I check for this
with
the Case-statements and, if the value is 0, set it to 30 (arbitrary
number,
just to prevent getting a 0-result).

Then, to round the field correctly, I use another calculation :
Round(field;Position_calc + 2)

It works OK, but I would like to know if there is another/easier/faster
way
to do this. Secondly, this doesn't work if the last significant digit is
a
"0" because Filemaker just discards any trailing zeroes, although they
are
significant.

Thanks,

Peter







Reply With Quote
  #8  
Old   
Bridget Eley
 
Posts: n/a

Default Re: Significant digits - any ideas ? - 08-09-2003 , 04:26 PM



Could you give me an example of the numbers you used and the results you got
and what you think they should be.

Bridget Eley

in article KV9Za.4174$M6.301248 (AT) newsread1 (DOT) prod.itd.earthlink.net, Shadenfroh
at shadenfroh (AT) yahoo (DOT) com wrote on 10/8/03 3:10 AM:

Quote:
Your calc is graceful. However, when I tried it, I didn't get the trailing
zeros to four significant digits.


Reply With Quote
  #9  
Old   
Bridget Eley
 
Posts: n/a

Default Re: Significant digits - any ideas ? - 08-10-2003 , 04:29 PM



Hi Shadenfroh

I understood Peter to mean that trailing zeroes were significant for the
purpose of identifying the digits on which to perform the round function. I
do not understand why he would need to leave the trailing zeroes in the
result, since 5.00023 = 5.0002300.

Where my calc does fall down is on whole numbers (returned ?), and negative
numbers (rounding up instead of down and down instead of up), both easy
enough to fix.

My revised calc:

If(Int(Number) = Number, Number,Left(Number, Position(Number, ".", 1, 1) -
1) & Abs(Round(TextToNum(If(Number < 0, "-.",".") & Right(Number,
Length(Number) - Position(Number, ".", 1, 1))),SignificantDigits))
/ TextToNum(Left("10000000000000000000", Length(Right(Number, 1 +
Length(Number) - Position(Number, ".", 1, 1))) -
Length(NumToText(TextToNum(Right(Number, Length(Number) - Position(Number,
".", 1, 1))))))))

Bridget Eley

in article hetZa.5162$M6.376337 (AT) newsread1 (DOT) prod.itd.earthlink.net, Shadenfroh
at shadenfroh (AT) yahoo (DOT) com wrote on 11/8/03 1:09 AM:

Quote:
F'rinstance, 5.00023000999 calculates to 5.00023 instead of 5.0002300

From Peter's post, "As to the seeming contradiction: I initially indicated
that *leading* zeroes (0 before the first non-zero digit) were
insignificant, but *trailing* zeroes (zero after the 3rd non-zero digit)
were not."


Reply With Quote
  #10  
Old   
Bridget Eley
 
Posts: n/a

Default Re: Significant digits - any ideas ? - 08-10-2003 , 05:04 PM



Previous calc didn't work.

This solves the whole number problem (still working on the other):

If(Int(Number) = Number, Number,Left(Number, Position(Number, ".", 1, 1) -
1) & Round("." & TextToNum(Right(Number, Length(Number) - Position(Number,
".", 1, 1))),SignificantDigits)/
TextToNum(Left("10000000000000000000", Length(Right(Number, 1 +
Length(Number) - Position(Number, ".", 1, 1))) -
Length(NumToText(TextToNum(Right(Number, Length(Number) - Position(Number,
".", 1, 1))))))))

Bridget Eley

in article BB5CF65C.261A%bridgeteley (AT) ihug (DOT) com.au, Bridget Eley at
bridgeteley (AT) ihug (DOT) com.au wrote on 11/8/03 7:29 AM:

Quote:
Where my calc does fall down is on whole numbers (returned ?), and negative
numbers (rounding up instead of down and down instead of up), both easy
enough to fix.


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.