Index
2017-07-30 17:38Gene Wirchenko : SET DECIMALS Gotcha
2017-07-31 05:34Laurie Alvey : Re: SET DECIMALS Gotcha
2017-07-31 06:19Laurie Alvey : Re: SET DECIMALS Gotcha
2017-07-31 07:04Ted Roche : Re: SET DECIMALS Gotcha
2017-07-31 07:42Darren : RE: SET DECIMALS Gotcha
2017-07-31 22:43Gene Wirchenko : Re: SET DECIMALS Gotcha
2017-08-01 05:10Laurie Alvey : Re: SET DECIMALS Gotcha
2017-08-02 08:16Laurie Alvey : Re: SET DECIMALS Gotcha
2017-08-02 09:10Ted Roche : Re: SET DECIMALS Gotcha
Back to top
SET DECIMALS Gotcha

Author: Gene Wirchenko

Posted: 2017-07-30 17:38:11   Link

Hello:

I have just been bitten by SET DECIMALS. (Is there really any

use for this besides making programming just a bit more difficult?)

I have a table with values to four decimal places. I use

<vfp>

transform(thevalue,"999999.9999")

</vfp>

to create the string representation. With SET DECIMALS set to its

default value, a value of 0.0123 is converted to " 0.0100" which

loses two digits of precision.

I had this problem with another data item that had more than

two decimal places. I wrote a special function to handle it by

setting SET DECIMALS to the number of decimal places I needed, doing

the transform(), and setting SET DECIMALS back to the default.

Why did I do that? Because the number of decimal places can

vary and I was generating a line of print in one line of code, BUT

also, because I really do not understand the point of SET DECIMALS.

Could someone please clue me in?

Sincerely,

Gene Wirchenko

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox

OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/21116b001f0e37ad4eee6e4feebab85f@mtlp000085

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2017 Gene Wirchenko
Back to top
Re: SET DECIMALS Gotcha

Author: Laurie Alvey

Posted: 2017-07-31 05:34:09   Link

SET DECIMALS TO n only works when SET FIXED is ON.

Laurie

On 30 July 2017 at 23:38, Gene Wirchenko <genew@telus.net> wrote:

> Hello:

>

> I have just been bitten by SET DECIMALS. (Is there really any use

> for this besides making programming just a bit more difficult?)

>

> I have a table with values to four decimal places. I use

> <vfp>

> transform(thevalue,"999999.9999")

> </vfp>

> to create the string representation. With SET DECIMALS set to its default

> value, a value of 0.0123 is converted to " 0.0100" which loses two

> digits of precision.

>

> I had this problem with another data item that had more than two

> decimal places. I wrote a special function to handle it by setting SET

> DECIMALS to the number of decimal places I needed, doing the transform(),

> and setting SET DECIMALS back to the default.

>

> Why did I do that? Because the number of decimal places can vary and

> I was generating a line of print in one line of code, BUT also, because I

> really do not understand the point of SET DECIMALS.

>

> Could someone please clue me in?

>

> Sincerely,

>

> Gene Wirchenko

>

>

[excessive quoting removed by server]

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox

OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/CAMvTR9fCAO86+k0Ypm15NoFfmQBdcoNuvEp8h4Pvdo9W1g166g@mail.gmail.com

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2017 Laurie Alvey
Back to top
Re: SET DECIMALS Gotcha

Author: Laurie Alvey

Posted: 2017-07-31 06:19:17   Link

This works:

x = 1.2345

SET DECIMALS TO 4

SET FIXED ON

? TRANSFORM(x, "999.9999")

Laurie

On 31 July 2017 at 11:34, Laurie Alvey <trukker41@gmail.com> wrote:

> SET DECIMALS TO n only works when SET FIXED is ON.

>

> Laurie

>

> On 30 July 2017 at 23:38, Gene Wirchenko <genew@telus.net> wrote:

>

>> Hello:

>>

>> I have just been bitten by SET DECIMALS. (Is there really any use

>> for this besides making programming just a bit more difficult?)

>>

>> I have a table with values to four decimal places. I use

>> <vfp>

>> transform(thevalue,"999999.9999")

>> </vfp>

>> to create the string representation. With SET DECIMALS set to its

>> default value, a value of 0.0123 is converted to " 0.0100" which loses

>> two digits of precision.

>>

>> I had this problem with another data item that had more than two

>> decimal places. I wrote a special function to handle it by setting SET

>> DECIMALS to the number of decimal places I needed, doing the transform(),

>> and setting SET DECIMALS back to the default.

>>

>> Why did I do that? Because the number of decimal places can vary

>> and I was generating a line of print in one line of code, BUT also, because

>> I really do not understand the point of SET DECIMALS.

>>

>> Could someone please clue me in?

>>

>> Sincerely,

>>

>> Gene Wirchenko

>>

>>

[excessive quoting removed by server]

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox

OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/CAMvTR9fuNvuHmXGm9kyHEyj8ikkNArihqVVrJK_oG7rTFWq3Ow@mail.gmail.com

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2017 Laurie Alvey
Back to top
Re: SET DECIMALS Gotcha

Author: Ted Roche

Posted: 2017-07-31 07:04:52   Link

>

> I have just been bitten by SET DECIMALS. (Is there really any use for

> this besides making programming just a bit more difficult?)

>

There may have been, when it was invented in the dBASE days. I believe

it does not affect values, only their display.

> I have a table with values to four decimal places. I use

> <vfp>

> transform(thevalue,"999999.9999")

> </vfp>

> to create the string representation. With SET DECIMALS set to its default

> value, a value of 0.0123 is converted to " 0.0100" which loses two

> digits of precision.

What if you multiplied the number by 10^4? Would the precision still

be there, only not displayed?

> I had this problem with another data item that had more than two

> decimal places. I wrote a special function to handle it by setting SET

> DECIMALS to the number of decimal places I needed, doing the transform(),

> and setting SET DECIMALS back to the default.

> Why did I do that?

That is probably the crux of the matter.

> BUT also, because I

> really do not understand the point of SET DECIMALS.

>

Is there someplace you could look it up? A reference guide of some sort?

--

Ted Roche

Ted Roche & Associates, LLC

http://www.tedroche.com

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox

OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/CACW6n4uK9XJcaFwuAfneQyMAmragXzbGaZ5jBBMJWbXvfpEhoQ@mail.gmail.com

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2017 Ted Roche
Back to top
RE: SET DECIMALS Gotcha

Author: Darren

Posted: 2017-07-31 07:42:00   Link

It makes a difference to the calculated value .... Only difference between

two functions below is one sets decimal to 2 and other to 16. The 16 version

produces expected results.

? DectoBase36_2(2176782335), DectoBase36(2176782335), "Expecting ZZZZZZ" &&

Returns "100000", "ZZZZZZ"

? DectoBase36_2(2176782334), DectoBase36(2176782334), "Expecting ZZZZZY" &&

Returns "100000", "ZZZZZY"

lnVal = 2176782335

SET DECIMALS TO 2

? INT(LOG(m.lnVal) / LOG(36)), "Expecting 5" && Returns 6

SET DECIMALS TO 16

? INT(LOG(m.lnVal) / LOG(36)), "Expecting 5" && Returns 5

FUNCTION DectoBase36

LPARAMETERS vnVal

LOCAL lnDecimals, lnPwr, lcString, lnMult, lnInt

STORE "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO lcValues

lndecimals = SET("DECIMALS")

SET DECIMALS TO 16

lnPwr = INT(LOG(m.vnVal) / LOG(36))

lcString = ""

FOR ln = m.lnPwr TO 0 STEP -1

lnMult = 36^m.ln

lnInt = INT(m.vnVal / m.lnMult)

vnVal = m.vnVal -(m.lnInt * lnMult)

lcString = m.lcString + SUBSTR(m.lcValues, m.lnInt + 1, 1)

ENDFOR

SET DECIMALS TO m.lndecimals

RETURN lcString

ENDFUNC

FUNCTION DectoBase36_2

LPARAMETERS vnVal

LOCAL lnDecimals, lnPwr, lcString, lnMult, lnInt

STORE "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO lcValues

lndecimals = SET("DECIMALS")

SET DECIMALS TO 2

lnPwr = INT(LOG(m.vnVal) / LOG(36))

lcString = ""

FOR ln = m.lnPwr TO 0 STEP -1

lnMult = 36^m.ln

lnInt = INT(m.vnVal / m.lnMult)

vnVal = m.vnVal -(m.lnInt * lnMult)

lcString = m.lcString + SUBSTR(m.lcValues, m.lnInt + 1, 1)

ENDFOR

SET DECIMALS TO m.lndecimals

RETURN lcString

ENDFUNC

-----Original Message-----

From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Ted

Roche

Sent: Monday, 31 July 2017 10:05 PM

To: profoxtech@leafe.com

Subject: Re: SET DECIMALS Gotcha

>

> I have just been bitten by SET DECIMALS. (Is there really any

> use for this besides making programming just a bit more difficult?)

>

There may have been, when it was invented in the dBASE days. I believe it

does not affect values, only their display.

> I have a table with values to four decimal places. I use <vfp>

> transform(thevalue,"999999.9999") </vfp> to create the

> string representation. With SET DECIMALS set to its default

> value, a value of 0.0123 is converted to " 0.0100" which loses two

> digits of precision.

What if you multiplied the number by 10^4? Would the precision still be

there, only not displayed?

> I had this problem with another data item that had more than two

> decimal places. I wrote a special function to handle it by setting

> SET DECIMALS to the number of decimal places I needed, doing the

> transform(), and setting SET DECIMALS back to the default.

> Why did I do that?

That is probably the crux of the matter.

> BUT also, because I

> really do not understand the point of SET DECIMALS.

>

Is there someplace you could look it up? A reference guide of some sort?

--

Ted Roche

Ted Roche & Associates, LLC

http://www.tedroche.com

[excessive quoting removed by server]

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox

OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/011f01d309fa$69f69cc0$3de3d640$@ozemail.com.au

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2017 Darren
Back to top
Re: SET DECIMALS Gotcha

Author: Gene Wirchenko

Posted: 2017-07-31 22:43:03   Link

At 03:34 2017-07-31, Laurie Alvey <trukker41@gmail.com> wrote:

>SET DECIMALS TO n only works when SET FIXED is ON.

I just tried it. It works regardless of the setting of SET FIXED.

[snip]

Sincerely,

Gene Wirchenko

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox

OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/792e05ddf193ac3359d90b22d9085468@mtlp000083

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2017 Gene Wirchenko
Back to top
Re: SET DECIMALS Gotcha

Author: Laurie Alvey

Posted: 2017-08-01 05:10:45   Link

That surprises me. I'll do some more tests.

Laurie

On 1 August 2017 at 04:43, Gene Wirchenko <genew@telus.net> wrote:

> At 03:34 2017-07-31, Laurie Alvey <trukker41@gmail.com> wrote:

>

>> SET DECIMALS TO n only works when SET FIXED is ON.

>>

>

> I just tried it. It works regardless of the setting of SET FIXED.

>

> [snip]

>

> Sincerely,

>

> Gene Wirchenko

>

>

[excessive quoting removed by server]

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox

OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/CAMvTR9fm-ERVjZNk4i4vw=+wztCq7_BRjq6_GtRYSbv5H9emFw@mail.gmail.com

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2017 Laurie Alvey
Back to top
Re: SET DECIMALS Gotcha

Author: Laurie Alvey

Posted: 2017-08-02 08:16:57   Link

Hi Gene,

You're right. In the past, I've had problems with SET DECIMALS in forms

with private datasessions. The problem went away when I set FIXED ON, but

it must have been something else.

Sorry for the misinformation.

Laurie

On 1 August 2017 at 11:10, Laurie Alvey <trukker41@gmail.com> wrote:

> That surprises me. I'll do some more tests.

>

> Laurie

>

> On 1 August 2017 at 04:43, Gene Wirchenko <genew@telus.net> wrote:

>

>> At 03:34 2017-07-31, Laurie Alvey <trukker41@gmail.com> wrote:

>>

>>> SET DECIMALS TO n only works when SET FIXED is ON.

>>>

>>

>> I just tried it. It works regardless of the setting of SET FIXED.

>>

>> [snip]

>>

>> Sincerely,

>>

>> Gene Wirchenko

>>

>>

[excessive quoting removed by server]

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox

OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/CAMvTR9dMF5ThbSP=c0JKFWuFHtxs9OLHkpjKfT6-12VU2A74sQ@mail.gmail.com

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2017 Laurie Alvey
Back to top
Re: SET DECIMALS Gotcha

Author: Ted Roche

Posted: 2017-08-02 09:10:38   Link

On Sun, Jul 30, 2017 at 6:38 PM, Gene Wirchenko <genew@telus.net> wrote:

> Hello:

>

> I have just been bitten by SET DECIMALS. (Is there really any use for

> this besides making programming just a bit more difficult?)

>

> I have a table with values to four decimal places. I use

> <vfp>

> transform(thevalue,"999999.9999")

> </vfp>

> to create the string representation.

If you use STR(thevalue,11,4), you should get the result you want.

--

Ted Roche

Ted Roche & Associates, LLC

http://www.tedroche.com

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox

OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/CACW6n4vQTWXYe_H0Z7h+3xH_Vpt4erSNr=GmchKCS-X7t-DMBg@mail.gmail.com

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2017 Ted Roche