Convertion of Decimal to Integer

Hi,

Is there a way in nav to Convert decimal to Integer.

Example: 101.23 to 101? hoping for your reply. Thanks

myint := 101.23 div 1;

Try this…

MyInt := ROUND(MyDec,1,’=’)

Thanks with regards.

IF My dec is 102.54 then myint should be 103 (not 102).

am I right ??[H]

I would say that depends on how the rules for rounding are.
You are right that ordinary rounding would make 102.54 round to 103, but sometimes you always want to round down (or up).

e.g.
When calculating payroll-taxes in Denmark, we always round down.
This way it’s always the government that end up as the “loser” in the rounding.

Thank you for your kind information Alexander.[:P]

You can alos use the DIV method to round correctly:

To always round down:
myint := 101.23 div 1;

To round up/down based on decimal (0.5):
myint := 101.23 + 0.5 div 1;

Rashed’s answer is the correct one, since the question was to CONVERT a Decimal to an Integer. Which generally implies pure truncation. The others are basically rounding a decimal to zero decimal places and then converting to an integer.

Be careful here. This will produce the wrong result if the number you wish to round is already integer valued.

I know, I usually do not do roundings that way :wink: