IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Paradox
Search Paradox Group:

Advanced
-Collapse +Expand Paradox To/From
To/FromCODEGuides
-Collapse +Expand Paradox Store
PRESTWOODSTORE

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBDesktop Data...Paradox & Ob...ObjectPAL Co...OPAL: Langua...   Print This     
  From the May 2015 Issue of Prestwood eMag
 
Paradox OPAL: Language Basics:
ObjectPAL Comparison Operators (=, <>)
 
Posted 15 years ago on 2/11/2009
Paradox Code Snippet:
 A flashcard from our Paradox Flashcards Library
 A code snippet from our Paradox Code Snippets Page

KB101875

General Info: Round Floating Point Numbers

When comparing floating point numbers, make sure you round to an acceptable level of rounding for the type of application you are using.

Languages Focus: Comparison Operators

A comparison operator compares two values either literals as in "Hello" and 3 or variables as in X and Counter. Most languages use the same operators for comparing both numbers and strings. Perl, for example, uses separate sets of comparison operators for numbers and strings.

ObjectPAL Comparison Operators

Common comparison operators:

= equal
<> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal

Syntax Example:
'Does ObjectPAL evaluate the math correctly? No!
If .1 + .1 + .1 = .3 Then
msgInfo("", "correct")
Else
msgInfo("", "not correct")
endIf

Overcoming Floating Point Errors

Because computers have trouble with certain floating point values (such as .1), you need to decide what level of accuracy is "good enough" for your application. Perhaps establish a standard for each application. For example, you could establish 6 decimal points as a standard and require all developers to use ObjectPAL's round() method when comparing floating point number. For example, you could rewrite the above routine as follows and get the result you expect.

If round(.1 + .1 + .1, 6) = round(.3, 6) Then
msgInfo("", "correct")
Else
msgInfo("", "not correct")
EndIf

More Info

Tip:  Round Floating Point Numbers

Comments

1 Comments.
Share a thought or comment...
Comment 1 of 1

Object PAL comparison operators are discussed on this blog page. Things are elaborated and discussed in a very detailed manner on this blog page. And also I found resumespice.com review service on this page which is incredible. Keep sharing more pages like that with us in the best regards of technology and the modern world.

Posted 51 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1116A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101875 Counter
19406
Since 2/11/2009
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]