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

numeric conversion

Status
Not open for further replies.

DanNorris2000

Technical User
Nov 10, 2000
186
US
Trying to convert some numeric data but not having much luck with the results.
I have a numeric field 4,0 called bookperiod
Sample: 200105
199903
200006

I would like to convert this to numeric 3,0
101
99
100 (dont ask why)

I tried the following:
Val(substr(str(Ledger.bookper),1,4))-1900 as bookyr
but my result was -1900

where did I go wrong?

 
Try this:

VAL(SUBSTR(STR(ledger.bookper,6),1,4))-1900 as bookyr

If I am correct, numbers are always right justified, so you end up with some leading spaces if you don't specify how long to make the string.
 
that results in a numeric 8,2
101.00
99.00
100.00
I would like to make the resulting numeric field to be 3,0
 
The default length of the result returned by the STR() function is 10. You're getting the value of the high-order blanks.

Jim
 
Toyed with the following (round((bookper/100),0)-1900
but ended up with a numeric 15,0
 
If you use the STR() function, VFP defaults to 2 decimals in a numeric value (SET DECIMALS is default 2).

You should use STR(number, length, number of decimals)

Or :

lcValue = ALLTRIM(STR(INT(MyNumber)))


In your case, assuming your values are always 6 numbers,

lnNewValue = INT(lnOldValue/100) - 1900


HTH,

Weedz (Wietze Veld)
My private project:CrownBase source code can be downloaded !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top