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!

Changing Numeric Data in a Field

Status
Not open for further replies.

gfath

Technical User
Jan 14, 2007
2
0
0
A2
Using foxpro to change large inventory database from delimited text file and exporting to excel file. Have one field i need to add decimal in it. example (12123) need to have 12.123 and its a numeric field
 
Let's assume the value you're working with is a character data type in VFP and is stored in a variable named lcx. Then if you need a numeric result you can simply do

Code:
VAL( lcx) / 1000

If you need a character string as the result you can do

Code:
STR( VAL(lcx)/1000, 10, 3)

where 10 is an arbitrary overall length for the result string. Alternatively you can use VFP's string functions, something like this:

Code:
LEFT( lcx, LEN( lcx) - 3) + "." + RIGHT( lcx, 3)

And if you need a numeric result from that just do a VAL() on the above:

Code:
VAL( LEFT( lcx, LEN( lcx) - 3) + "." + RIGHT( lcx, 3))



 
If you are using VFP9, look up CAST() function. Do not remember if it was available in 8
t = "100.25"
? vartype(t) **** C
z = CAST(t as N(10,3)
? vartype(z) ****N
**** In a SQL Select
**** "cField", needs to be converted to Numeric
Select <<field1>>,<<field2>>,CAST(cField as N(10,3)) As nField from <<tablename>>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top