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

Parsing numeric values 1

Status
Not open for further replies.

white605

Technical User
Jan 20, 2003
394
US
Given a numeric value 1234.56
Is there a way to parse the digets from it without first converting it to a string and looping thru it with subs() seven times and extracting one character at a time?
I am preparing values to populate machine readable blocks on a pdf tax form.
wjwjr
 
Sorry, code i am using below - Public statements to check the output.

Code:
CREATE TABLE test2.dbf (total_b n(10 ,2), s4130 n(10,2), ototal n(10,2))
INSERT INTO test2.dbf (total_b, s4130, ototal) values(1000.00, 500.00, 100.00)
INSERT INTO test2.dbf (total_b, s4130, ototal) values(1000.00, 500.00, 100.00)
INSERT INTO test2.dbf (total_b, s4130, ototal) values(1000.00, 500.00, 100.00)

SELECT ;
    ROUND(SUM(TOTAL_B),2) AS SALES, ;
    ROUND(SUM(S4130) + SUM(OTOTAL),2) AS TAXABLE, ;
    ROUND((SUM(TOTAL_B))-(SUM(S4130)+SUM(OTOTAL)),2) AS DEDUCT, ;
    ROUND((SUM(S4130)+SUM(OTOTAL))*(.05),2) AS TXAMOUNT, ;
    ROUND(((SUM(S4130)+SUM(OTOTAL))*(.05))*(.02),2) AS TXDISC, ;
    ROUND((((SUM(S4130)+SUM(OTOTAL))*(.05))-(((SUM(S4130)+SUM(OTOTAL))*(.05))*(.02))),2) AS TAXDUE ;
    FROM TEST2 INTO TABLE test3.dbf

USE test3
gnFieldcount = AFIELDS(gaMyArray)  

FOR nCount = 1 TO gnFieldcount 
  cmv = gaMyArray(nCount,1)  
  cvalue = STR(&cmv,7,2)
  	FOR ncount2 = 1 TO 7
  		DO case
  			CASE ncount2 = 1
  				STORE cmv+[X000D00] TO CVNAME  && use X to call the proper diget when filling in blocks
  											   && use D in string - will not accept .	
  				PUBLIC &CVNAME
  				STORE SUBSTR(cvalue,ncount2,1) TO &CVNAME &&store thousands digit
  			CASE ncount2 = 2	
   				cvname=cmv+[0X00D00]
  				PUBLIC &CVNAME
  				STORE SUBSTR(cvalue,ncount2,1) TO &CVNAME  &&store hundreds diget
  			CASE ncount2 = 3	
  				cvname=cmv+[00X0D00]
  				PUBLIC &CVNAME
  				STORE SUBSTR(cvalue,ncount2,1) TO &CVNAME
			CASE ncount2 = 4
  				cvname=cmv+[000XD00]
  		 		PUBLIC &CVNAME
  				STORE SUBSTR(cvalue,ncount2,1) TO &CVNAME
			CASE ncount2 = 5
  				cvname=cmv+[0000D00]
  				PUBLIC &CVNAME
  				STORE SUBSTR(cvalue,ncount2,1) TO &CVNAME
			CASE ncount2 = 6
  				cvname=cmv+[0000DX0]
  			 	PUBLIC &CVNAME
  				STORE SUBSTR(cvalue,ncount2,1) TO &CVNAME
			CASE ncount2 = 7
  				cvname=cmv+[0000D0X]
  				PUBLIC &CVNAME
  				STORE SUBSTR(cvalue,ncount2,1) TO &CVNAME

  			ENDCASE
  		ENDFOR
ENDFOR
DISPLAY MEMORY
 
I can envise a way - something along lines
Code:
x1 = 1234.56
x = x1 * 1000
FOR m = 1 TO 6
  PRINT INT(x / 10 ^ m), INT(x / 10 ^ (m + 1)) * 10,
  d = INT(x / 10 ^ m) - INT(x / 10 ^ (m + 1)) * 10
PRINT d
NEXT

Output:
Code:
 123456        123450        6
 12345         12340         5
 1234          1230          4
 123           120           3
 12            10            2
 1             0             1

(sorry it's qbasic but it should give you the idea)
No digital point sorry.

But what's wrong with converting to string?
 
Hi White,

I don't unserstand why do you need the single digits? Is there a field for each digit in the pdf form or why?

You can't access a number as an array of digits and I know of no other language capable to do so. You can access single characters of strings in several langages.

So what's wrong with STR() and what's wrong with a loop and substr()?

What for do you need your big case statement? Do you really need vars named that way? Why not simply build an array? You're using arrays already, why not consequently?

Code:
...
local array ladigits[gnFieldcount,7*2]
local cmv, cvalue
For nCount = 1 TO gnFieldcount 
  cmv = gaMyArray[nCount,1]  
  cvalue = STR(&cmv,7,2)
  For ncount2 = 1 to 7
    ladigits[nCount,nCount2*2-1]=cmv+iif(ncount2=5,[0000D00],stuff([0000D00],nCount2,1,"X"))
    ladigits[nCount,nCount2*2]=SUBSTR(cvalue,ncount2,1)
  Endfor ncount2
Endfor nCount
DISPLAY MEMORY Like laDigits

Bye, Olaf.
 
tsh73
"But what's wrong with converting to string?"
I knew there was a way to do it with math, just couldnt get it right. There is a way! thanks

Olaf,
Each diget has to be places in a seperate block on the pdf form via automation. The reason for the names is so I can remember what to map to what with the "x" being the diget the variable contains and the name the line it goes on.

Since i have to do this for many lines your code that replaces the case statement will be helpfull - thanks
I will try it and get back.

wjwjr
 
if the spaces on the form are multiple of 6CPI,10CPI, etc. blocks and you have to fill up a straight line you might try transform(12345.67,"9 9 9 9 9 9 9 . 9 9") format. and courrier fonts.

try it.

nasib kalsi







 
Nasib,
I bet there are
I also bet youve filled forms like that in before. This should save lots of time!
wjwjr
 
thanks white605.

yes, i did play with forms a few years ago, and a lot, but did not use this format. my problem always was verticle allignment. it will never allign on a multipart(5) form on a dot matrix. however, almost for every possible situation, i look at this function and try to use it. glad it helped.

if it still does not fill up properly then use
alines function like alines(a_digits,transform(123456.78,"9 9 9 9 9 9 . 9 9"),' '). with this you can do whatever you want.


nasib kalsi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top