Skip to main content

Problem:

How can I compute Square Roots and Cubed Roots?

Resolution:

To find the square root of a number in RM/COBOL, use this statement:

compute RESULT rounded = NUMBER ** 0.5

Use 0.33 for the cubed root.

The "rounded" phrase is needed because the number 4 returns a root of 1.99..., only bigger numbers (9 and up) return the correct whole number for the root without rounding.

The **  operator performs exponentiation when used with a whole number instead of a decimal.

    

Old KB# 6113