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!

Bug in NumericText Function?

Status
Not open for further replies.

asmetana

MIS
May 7, 2001
15
US
I am using the numerictext function to see if a string represents a number. The problem is numerictext("+3") [positive 3] returns FALSE. It should return TRUE. Numerictext works correctly for [negative 3] i.e. numerictext("-3") returns TRUE.

Have other people run into this? If so, what was your work around?
Thanks
 
Hi asmetana,
I just checked it. You are right. I think it is a bug.
 
It's not really a bug, just something that may drive you buggy. [smile]

3 is positive, it doesn't need the "+". -3 needs the "-" to indicate that it is negative.

Mike
 
interesting...never saw that before

I suppose you have to have a formula like this then to evaluate your situation

Whileprintingrecords;

if left({Table.stringfield},1) = "+" then
(
if isNumeric (right({Table.stringfield},
len({Table.stringfield} -1))then
***do something***
else
***do somethingelse***;
)
else
(
if isNumeric ({Table.stringfield}) then
***do something***
else
***do somethingelse***;
)



Jim Broadbent
 
I am not sure I agree that it is not a bug. While the plus sign is optional to designate a positive number, including it still represents a vaild number.

Just one more thing to have to code around while addressing my real problem: Crystal Reports doesn't recognize scientific notation (1.23E-08). To address this, I am writing a set of custom functions to handle them and that is where the numerictext problem surfaced.

Andy
 
Noglem,

What the coding is starting to evolve to is:

stringvar str :=replace({table.textcolumn}," ",""); //remove blanks
if str[1] = "+" then str := replace(str,"+"," ");
if numerictext(str) then
.
.
 
sure you could do it that way too...my way would work just as well

As far as crystal bugs go....there are many Crystal "Oddities" but at least once they are identified there is always a work around

Jim Broadbent
 
I agree with mbarron, placing a + in front of a positive number is redundant and not a standard, so expecting to have coded for that is overly optimistic.

Along the lines of the workarounds posted, try:

numerictext(replace(trim({table.field}),"+",""))

This should also eliminate any offending spaces. Since the designers saw fit to include the redundant + sign, I would check for other irregularities...

-k
 
The following will convert "regular" string numbers and scientific notation in the form of #.##E+## (or ##E-##) to a number. Crystal limits (CR 8 at least) are 16 digits before the decimal and 10 after.

stringvar scinot:={@field} ;
numbervar ord;
numbervar out;
numbervar posneg:=1;

if left(scinot,1)="-" then
posneg:=-1;

ord:=abs(val(scinot));

if instr(scinot,"+")>0 then
out:=10^val(right(scinot,2))*ord else

if instrrev(scinot,"-")>1 then
out:=((1/10)^val(right(scinot,2)))*ord else

out:=abs(val(scinot));

posneg*out;

Mike
 
Thanks Mike,

You gave me an idea that I have implemented below. It seems to work (at least for the dozen different test cases i have tried.

//convert a numeric string, which may be in scientific notation, to a number
//

numbervar strlen;
numbervar eloc;
stringvar str := replace({table.field}," ",""); // remove blanks

if NumericText (str) then
tonumber(str)
else
(
strlen := len(str);
eloc := instr(str,"e",1);
str:=replace(str,"+"," ");
tonumber(str[1 to (eloc-1)]) * 10^ tonumber(str[(eloc+1) to strlen]);
)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top