Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SET DECIMALS TO is used if SET FIXED is OFF ?
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00850956
Message ID:
00852429
Views:
16
Hi Garrett,

-------
Interesting. One question, though:

> varDec1 = 3.1255
> varDec4 = 2.5567
> ? 'literal product ',3.1*2.5567 && i aspected 4 decimals
> ? 'literal division ',3.1/2.5567 && i wish full decimals
> ? 'variable division ',m.varDec1/m.varDec4 && i wish full decimals
> ? 'integer exponentation ',3.1^8 && i wish 8 decimals
> ? 'fractional exponentation ',3.1^2.5567 && i wish full decimals
-------

A typed error:
? 'literal product 		',3.1*2.5567	&& i aspected 5 decimals
-----------
Did you mean the numbers in the above to match -- in other words, did you intend to use 3.1255 in your literals, as well as your variables?
-----------

Numbers are not important, important is the rules that VFP use for set result decimals;
rule change with type operation and type of source.

Code for focus on division
SET FIXED OFF
SET TALK OFF
CLEAR

FOR nDec=0 TO 11 STEP 5
	? TRANSFORM(m.nDec,'@R -------- SET DECIMAL TO 99 ----------')

	SET DECIMALS TO m.nDec

	varDec1 = 3.1255
	varDec4 = 2.5567
	
	? 'literal division		',3.1255/2.5567
	? 'literal division		',3.1255/m.varDec4
	? 'literal division		',m.varDec1/2.5567
	? 'variable division	   ',m.varDec1/m.varDec4				&& you can see another problem, ? command put N*NumVariables spaces
	RELEASE varDec1,varDec4
NEXT
?
? '******* Rule to compute decimals on division *******'
? 'literal division		decResult = MAX(sum(decItems),setDecimal)'
? 'variable division	decResult = MAX(4,setDecimal+2)'
If you want my opinion, the best choice, for any computation, is:

decResult = MAX(decimalForExpression,setDecimaltoValue)

because with SET DECIMAL TO 0 i can remove the MAX and use only decimalForExpression,
or i can set a minimum decimal for any computation.

For decimalForExpression math rules can to be used ( and VFP use they in some cases):
addition : MAX(member1Decimal,member2Decimal,...)
product  : SUM(member1Decimal,member2Decimal,...)
...
The principle is : only 1 rule that the developer it must remember

This is only my opinion, for simplified my job.

Fabio
Previous
Reply
Map
View

Click here to load this message in the networking platform