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

Advanced
-Collapse +Expand ASP Classic Store

Prestwood eMagazine

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

   ► KBWebsite Scri...ASP ClassicTool Basics   Print This     
  From the February 2014 Issue of Prestwood eMag
 
ASP Classic Tool Basics:
ASP Classic Comparison Operators (=, <>)
 
Posted 16 years ago on 11/10/2008 and updated 10/15/2009
ASP Classic Code Snippet:
 A flashcard from our ASP Classic Flashcards Library
 A code snippet from our ASP Classic Code Snippets Page

KB101585

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.

ASP Classic Comparison Operators

Save as VB Classic. Common comparison operators:

= equal
<> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal
Syntax Example:
//Does ASP evaluate the math correctly? No!
If .1 + .1 + .1 = .3 Then
Response.Write "correct"
Else
Response.Write "not correct"
End If

The Fix

There are several techniques for handling computer rounding errors. For ASP Classic, consider using the Round function. For example:

If Round(.1+.1+.1, 4) = .3 Then
  Response.Write "yes" & "<br>" 'Yes is displayed!
Else
  Response.Write "no" & "<br>"
End If

Reserve Floating Point Values

Because computers have trouble representing floating point values, you may want to reserve the use of floating point literals for imprecise measurements such length, height, weight, etc. The very nature of measurements is imprecise.

More Info

Tip:  Round Floating Point Numbers

Comments

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

thank you, you saved my day !

---
mathiew
Posted 9 years ago

Comment 2 of 2

I have been looking for information on this subject. I found your post well-written and informative. Thank you!

usa map

Posted 43 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 #101585 Counter
28867
Since 11/10/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


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