Use decimal directive
The use decimal pragma is used to provide a DecimalContext instance at the surrounding frame for configuring the decimal data type.
var ctx:DecimalContext, x:decimal
ctx = new DecimalContext(12, "half_even") // 12 digits of precision,
// round to even
{
use decimal ctx
x = a + b // "+" rounds to even if necessary
}
This affects not only the lexical scope, but also external function calls that are called subsequently from the same scope or nested scopes during runtime.
Note: Internally functions receive a hierarchical environment frame reference, which is decently optimized, where every frame contains a ?context local that includes a
DecimalContextreference that may be a null pointer (which means skip to parent frame).Thus, that syntactic construct should work with both synchronous and asynchronous code.
Syntax
-
UseDecimalDirective :
-
use decimal ListExpressionallowIn