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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retaining Precision with STR and TRANSFORM

Status
Not open for further replies.

LindaRichard

Programmer
Feb 23, 2001
103
0
0
CA
I have a series of numbers with various precisions:

For example
a(1)=12.34
a(2)=134.234
a(3)=1343456543.343234323

I wan't to transform these numeric values into strings
but I want to retain the original precision.

I know that for example, if I wanted to round to 2 digits
I could use
sTemp=str(a(1),4,2) this would yield "12.34"

The issue is that I don't know what precision will be
entered and I wan't to retain the value as it has been
entered.

I tried TRANSFORM and it works for the first two examples
"12.34"=TRANSFORM(a(1))
"134.234"=TRANSFORM(a(2))


but the third one gets padded with 0's after 16 digits
"1343456543.343234000" and the value is lost.

Does anyone have any suggestion on how to handle this.
VFP allows us to create numeric value of up to 20 in length
and 19 decimals, but the transformation to a string seems to
be limited to 16.

Thanks for your help

Linda


 
Linda,
Unfortunately, VFP internally stores "big" numbers in a 64-bit real format, and that limits the number of decimals to 16 (actually 15.95!) See the Help file topic "Visual FoxPro System Capacities" for more information.

If you want higher precision, don't convert them to an internal format.

Rick
 
Thanks for taking the time to answer my
question. I guess this means that there is no
way of transforming very long numbers into strings
in VFP.

Thanks
Linda
 
No, but if you want them to "remain as entered", then let them be entered as a string... This may reverse the proble to the problem of converting a string to a number...

Bye, Olaf.
 
Actually, many other program languages have an assortment of numeric types and each must be converted to be copied ot compared to another. I have code which reads and writes between ASP and VFP COM-compliant executables. After trying to keep track of which shared variables were which data type, I settled on defaulting to string type as the default and then whichever program picks up the data knows to handle it as string type, a common denominator so to speak. Life became much simpler after that.

In your case, you could examine the string value entered to see exactly what was typed in or sent. Getting the number of decimal places would therefore be simple to calculate.

x="12345.123456789"
y=AT(".",x)
? "Decimals = "+IIF(y=0,0,LTRIM(STR(LEN(SUBSTR(x,y+1)))))

dbMark
 
Thanks to all of you for your comments.
I'll go with the string entry approach.

Linda
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top