Previous Topic: snmpOctetStringFloat FunctionNext Topic: snmpRound Function


snmpProtectedDiv Function

This function divides two Double values and returns the result of the division as a Double. If the dividend or divisor is null or 0.0 the return value is 0.0. Use this function to protect the expression from dividing with null or 0. Data Repository can contain null or zero values, such as when a poll fails. In this case you avoid a divide-by-zero exception by using this function.

Syntax

This function has the following format:

Double snmpProtectedDiv(Double val1, Double val2)

Parameters

val1

Is the dividend. This is a Double value (floating number) to be divided by val2. (Double is a Java data type.)

val2

Is the divisor. This is a Double value (floating number). (Double is a Java data type.)

Return Values

Returns the result of the division as a Double or 0.0 if the dividend or divisor is null or 0.0 (Double is a Java data type).

Examples

The following expression produces the following result for a val1 of 7.2 and val2 of 2:

Expression:

snmpProtectedDiv(val1, val2)

Result:

3.6

The following expression produces the following result for a val1 of 7.2 and val2 of null or 0.0:

Result:

0.0

Advanced Example

The following expression is taken from Vendor Certification:

Utilization=snmpProtectedDiv((cpuStatsUser + cpuStatsSys),(cpuStatsUser + cpuStatsSys + (isdef(cpuStatsWait)?cpuStatsWait:0) + cpuStatsIdle))*100