Rounding decimal values
As Navision is a financial system, it's obvious that most of the time we need to handle decimal values, and rounding decimals is a very important part of it. When we are converting high-value currency to low-value currency, a small decimal can make a big difference.
How to do it...
Let's get started by creating a new codeunit from Object Designer.
Add the following global variables:
Name
Type
AmountToRound
Decimal
RoundToNearest
Decimal
RoundToUp
Decimal
RoundToDown
Decimal
Now write the following code in the
OnRun
trigger of the codeunit:AmountToRound:=345.8689999999; RoundToNearest:=ROUND(AmountToRound,0.01,'='); RoundToUp:=ROUND(AmountToRound,0.01,'>'); RoundToDown:=ROUND(AmountToRound,0.01,'<'); MESSAGE('Amount Before Rounding = %1 \\Rounded to nearest value = %2'+'\Rounded to upper value = %3\Rounded to lower value = %4',AmountToRound,RoundToNearest,RoundToUp,RoundToDown);
It's time to save and close the codeunit.
On execution of the...