From the February 2014 Issue of Prestwood eMag
ASP Classic Tool Basics:
ASP Classic Comparison Operators (=, <>)
Posted 11/10/2008 on 11/10/2008 and updated 10/15/2009
ASP Classic Code Snippet:


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"
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!
  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.


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

thank you, you saved my day !

Posted 11/20/2015
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 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 For service: 916-726-5675
Copyright (C) Prestwood IT Solutions.
All Rights Reserved.
Printed 9/30/2020