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

Numeric data type

Status
Not open for further replies.

oldbowler

Programmer
Mar 13, 2003
14
US
If I have a table with a field defined as N(5,1). I would expect the field to be able to contain a max value of 999.9. Why will FoxPro allow me to "replace" the field with 99999 but only allow 999.9 in a browse.
 
Well the simple answer is "because that's the way dBaseII did it!".

Unlike some langages (COBOL and FORTRAN) come to mind, the number of decimals in xBase is not really fixed or "implied", it's actually based on how where the decimal point is stored in the field. And while you can cheat with a replace, the Browse or Grid use the table definition to know where the decimal is supposed to be.

Rick

 
Mike,

FoxPro is not chopping of the leading digits. It will store the entire number.

Try:
create cursor test(fld n(5.1))
append blank
replace fld with 12345
browse

You will see that the value of fld is 12345.

It appears to me that FoxPro thinks its a 5 position numeric field that can possibly store 1 decimal.

My real problem is this field is in a cursor that is updating a SQL table with a numeric field defined as 4,1 and when I do the SQL replace, SQL gives me an error. I would expect FoxPro to give me the error before SQL.
 
You can always build your own validation routine using AFIELDS() and allow for a max allowed value of VAL(REPLICATE([9],FieldLen-(DecimalsN+1))+[.]+REPLICATE([9],DecimalsN)) and a min allowed value of VAL([-]+REPLICATE([9],FieldLen-(DecimalsN+2))+[.]+REPLICATE([9],DecimalsN)) for numerica data types.

Brian
 
Thanks to all.

I know that data validation is my responsibility. I was just surprised that FoxPro does not follow numeric field definition.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top