Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

You need to determine whether a number is positive or negative, or you need to find the absolute value of a number.

The sgn() function takes a number as its single parameter. The sgn() function will return 1 if the number is positive, 0 if the number equals 0, and -1 if the number in negative:

<cfset testVar = sgn(-127)>
<cfoutput>#testVar#</cfoutput>
-1

The abs() function also takes a number as its single parameter. The abs() function will return the absolute value (the value of the number without its sign) of the number:

<cfset testVar = abs(-127)>
<cfoutput>#testVar#</cfoutput>
127


This question was written by Jeremy Petersen.
It was last updated on January 9, 2006 at 9:55:07 AM EST.

CFML Referenced

Abs()
<cfoutput>
Sgn()

Categories

Numbers

Comments

There are no comments for this entry.