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

Exponents

Status
Not open for further replies.

garths2

Programmer
Jan 15, 2002
57
0
0
US
I am using the "Val" function in Crystal to convert a string containing an exponent to a number. Val, however, only returns the number preceding the exponent:

i.e. val("9.99E4") is returning 9.99

I am expecting 99900 back.

What am I doing wrong?

Thanks in advance,

GS
 
Val is designed to stop reading the string when it finds the first character in the string that it finds that it can not recognize as a number or as a space.

You can not use Val to do what you want. You will have to write a formula. The formula will be something like:

Dim e as string
Dim es() As String
Dim Mantissa As Number
Dim Power as Number

e = "9.99E37"

Es = Split(e,"E")

Mantissa = ToNumber(Es(1))
Power = ToNumber(Es(2))

Formula = Mantissa * (10^Power)
 
I find it hard to believe I have to do a work around, since the "val" function does exactly what I expect in VB. Crystal documentation for the "val" function says:

"This function is designed to work like the Visual Basic function of the same name."

Is "E" not the standard notation for exponent. Why does it work with VB and Oracle just fine?

GS

 
That is how Seagate documents Val and that is how it works. You can not assume because the function is named the same it will work the same. Seagate does not make that claim. That is why they are called Crystal functions.
 
Did you not read the Crystal help file for the "val" function? Yes, it did make the claim:

"This function is designed to work like the Visual Basic function of the same name."


Besides this claim they made in their documentation, every other application I have used recognizes "E" as the notation for exponent.
 
I never pay attention to the comment section. In many cases they may contain outdated or inaccurate info.
The most important thing to read is the Action section. That tells you how the function operates.
 
You seem to be ignoring the the fact that "E" is the IEEE standard for exponent notation. Are you saying that Crystal is beyond standards?
 
I am just saying that I read the how the function works and use it accordingly.
 
garths2,

Geez, JoeCrystal hasn't said anything except to give you a workaround and to point out that one line in the Crystal help could be misleading.

You're inferring the purpose of the Val function based on the comment in the help, when its obviously not working that way and its not how the rest of the help article describes it. Val is designed to CONVERT STRINGS TO NUMBERS, not exponents to decimal format. The example shows an address field, and how can one function be smart enough to distinguish between exponents or a random string that has a number then the letter 'E' then more numbers.

The comment is misleading, but its not the first bug or misdocumented feature in Crystal, and it won't be the last one.
 
RoberKaiserIII asks, "...and how can one function be smart enough to distinguish between exponents or a random string that has a number then the letter 'E' then more numbers."

...seems VB's val() function and Oracle's to_number() function are "smart enough".

If Crystal's help comments are not accurate, out of date, and unreliable, why should we take the remainder of the articles (usage, action, and examples) seriously? As programmers, we rely heavily on commercial product documentation as well as acurately and thoroughly document our own programs.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top