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!

function val in fox pro

Status
Not open for further replies.

orchidee_h

Programmer
Dec 22, 2017
1
TN
how can i convert a string ch to float variable a use th function val(ch) but it return a numeric variable expl val(25.12) retrun 25 thanks for your help
 
VAL(25.12) causes error 11.

In your locale, is the decimal point really a decimal point, or is it a comma?
VAL("25.12") returns 25.12, if SET("POINT") is "."

So VAL is respecting the locale format of numbers.

If you want your number to be evaluated as source code, always needing the point as the decimal point, then you may use EVAL(), though that opens a can of worms for strings not numeric. CAST("25.12" as double) will also work even with SET POINT TO ",". Needs VFP8 or 9, not sure. I'm just sure CAST() did not exist in VFP7 or earlier.

Just a side note: CAST is a very usual function or SQL clause for databases. It has a non-standard way of "parameterization" of initial value and target type separated with AS instead of a comma, so I don't consider it a normal function, but more of an SQL clause, just like BETWEEN has two parameters separated by an AND with a non-boolean meaning, so these things are rather the quirky nature I always attribute to the SQL language in it's aim to sound more natural than normal code. Still, CAST() is listed in the VFP help under Language Reference and the subtopic of Functions.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top