I.T. Discussion Community!
 Message Board
 Members Only

#### Prestwood eMagazine

February Edition
Subscribe now! It's Free!

 ► KB ► Desktop Data... ► Paradox & Ob... ► ObjectPAL Co... ► OPAL: Langua...
From the May 2015 Issue of Prestwood eMag
 Paradox OPAL: Language Basics:ObjectPAL Comparison Operators (=, <>)
Posted 10 years ago on 2/11/2009
 To/From Code Guide: ObjectPAL Comparison... vs. Other Languages  A flashcard from our Paradox Flashcards Library  A code snippet from our Paradox Code Snippets Page

### 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`

 Tip: Round Floating Point Numbers

Share a thought or comment...

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 15952 Since 2/11/2009
-
 Contact Us! PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too! --Mike Prestwood
 Who's Online!