PrecisionEvaluate

Description

Evaluates one or more string expressions, dynamically, from left to right, using BigDecimal precision arithmetic to calculate the values of arbitrary precision arithmetic expressions.

Returns

An object; the result of the evaluations.

Function syntax

PrecisionEvaluate(string_expression1 [, string_expression2 , ... ])

See also

Evaluate, Using Expressions and Number Signs in the Developing ColdFusion Applications

Parameters

Parameter

Description

string_expression1, string_expression2...

Expressions to evaluate

Usage

The PrecisionEvaluate function lets you calculate arbitrarily long decimal (BigDecimal precision) values. BigDecimal precision arithmetic accepts and generates decimal numbers of any length, and does not use exponential notation.

The PrecisionEvaluate function calculates arbitrary precision results only for addition, subtraction, multiplication, and division. If you use any of the following operations, ColdFusion performs normal integer or floating point arithmetic and does not return BigDecimal values.

  • exponentiation (^)

  • modulus (MOD or %)

  • integer division (/)

This function differs from the Evaluate function only in its use of BigDecimal precision arithmetic to calculate numeric values; otherwise the two functions are identical. The results of an evaluation on the left can have meaning in an expression to the right, and the function returns the result of evaluating the rightmost expression. If a string expression contains a single- or double-quotation mark, the mark must be escaped.

If an expression, such as 1/3, results in an infinitely repeating decimal value, ColdFusion limits the decimal part to 20 digits.

Note: To increase processing efficiency, do not put the arithmetic expressions to evaluate in quotation marks (“). ColdFusion compiles PrecisionEvaluate(a*b) more efficiently than it compiles PrecisionEvaluate("a*b"), although both formats produce the same results.

Example

<h3>PrecisionEvaluate Example</h3> 
<cfif IsDefined("FORM.myExpression")> 
    <cftry> 
        <!--- Evaluate the expression and display the result. ---> 
        <cfset theExpression = PrecisionEvaluate(Form.myExpression)> 
        <cfoutput> 
            The value of the expression #FORM.MyExpression#  
            is #theExpression#.<br> 
        </cfoutput> 
 
        <cfcatch type="any"> 
            <cfoutput>Could not evaluate the expression #Form.myExpression#. 
            </cfoutput> 
        </cfcatch> 
    </cftry> 
</cfif> 
 
<cfform preservedata="yes"> 
    <h3>Enter a ColdFusion expression for evaluation.</h3> 
    <p>Try using some really big decimal numbers.</p> 
    <cfinput type="text" name="myExpression" size="60"><br> 
    <br> 
    <cfinput type="submit" name="submit"> 
</cfform>