nuk@wpi.WPI.EDU (Jacob W Anderson) (10/31/90)
I am having a very severe problem, well severe to me. I am trying to take a string which represents a real integer (from a resource file) and convert it to its real value (like the VAL function in BASIC). The problem is that it works for some values (up to 999.999) but after that it gives me numbers that do not even come near actual representation to the original string. Here is my code: Program Convert; VAR plusser:real; input:str255; output:real; index:integer; dec_position:integer; len:integer; cval:longint; exponent,n_exponent,p_exponent:integer; FUNCTION Pow(base,raise:integer):real; VAR go:integer; cur:real; BEGIN cur:=1.000; IF raise > 0 THEN BEGIN FOR go:=1 TO raise DO cur:=cur*base; END; IF raise < 0 THEN BEGIN FOR go:=1 to abs(raise) DO cur:=cur / base; END; IF raise = 0 THEN cur:=1.0; Pow:=cur; END; BEGIN output:=0; writen(chr(12)); REPEAT writen('Please enter a real value:'); readln(input); IF input <> 'end' THEN BEGIN len:=length(input); dec_position:=pos('.',input); p_exponent:=dec_position - 2; n_exponent:=len - dec_position; FOR index := 1 TO len DO BEGIN IF index = dec_position THEN BEGIN index:=index + 1; END; cval:=0; cval:=ord(input[index]) - 48; plusser:=cval * Pow(10,p_exponent); output:=output + plusser; p_exponent:=p_exponent - 1; END; UNTIL input = 'end'; END. I have tried the StringToNum(arg1:str255,VAR agr2:longint) but have gotten the same results. Please, if possible, mail to me at: nuk@wpi.wpi.edu thanx.