Variable currency values are especially useful when you need to perform calculations that require several digits of precision. This section provides information about using variable currency values in scripts.
To use a variable currency value as a local variable, use the keyword vcurrency. For example, the following statement declares a local variable currency value.
local vcurrency interest_rate;
You can perform calculations with variable currency values much like you perform calculations with standard currency values. All currency functions such as round() and truncate() work properly with variable currency values.
To ensure no precision is lost when performing calculations, intermediate variable currency results can have up to 39 digits with up to 15 decimal places. The number of digits and decimal places is determined by the value being calculated.
When performing calculations with currency or variable currency values, the final results often must be rounded. You can use the round() function to round individual values. You can also use the default roundmode to statement to specify the default rounding characteristics for all calculations in a specific script.
If precision is important in a calculation, you may want to retrieve the characteristics of a specific variable currency field or value. Use the precision() function to retrieve the number of digits a variable currency field or variable can store. Use the scale() function to retrieve how many decimal places a variable currency field or variable has.