Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with SET DECIMALS

Status
Not open for further replies.

SGLong

Programmer
Jun 6, 2000
405
US
This is probably one of those situations where I can't see the forest for the trees, but it's been driving me crazy for two days now. I have the following lines of code:

set decimals to 9
rtnval=transform(val(workval),'999,999,999.999999999')

When I write the rtnval to a text file there are only 8 decimals instead of 9 and I need that extra position. What am I overlooking?


 
Hi SGLong,

There are literally dozens of ways you could do this.

lcDecTargLen=9
lcPoint=SET('POINT')
lcDecPos=RAT(lcPoint,workval)
lcLen=LEN(workval)
lcDecLen=lcLen-lcDecPos
lcOutput=PADR(workval,(lcDecTargLen-lcDecLen+lcLen),'0')
? lcOutPut

If you are trying to determine why you are losing the last decimal position, post your code that writes rtnval to a text file.

Are you using:

FOPEN()/FWRITE()
or
SET ALTERNATE/?/??
or
STRTOFILE lAdditive Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
JonScott8

My code to output the information is extremely lengthy, as I'm processing 572 'fields' between 14 tables and sending them out with the STRTOFILE command. There are 572 calls to a bunch of procedures, one of which contains the two lines of code shown above. The calls are basically "m.variable=parse_string()", and then m.variable is concatenated to the string that will eventually be written out.

I wish I could be more descriptive, but without posting all 1478 lines of code that's the best I can do.

Steve
 
From VFP Help
"SET DECIMALS specifies the minimum number of decimal places used to display the results of division, multiplication, and trigonometric and financial functions."
Therefore trying to use Set Decimals to display or use to a integer will not work.
What you want is combination of SET DECIMALS, SET FIXED and SET DATASESSION. David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top