Rounding of Decimal to Int

An interesting topic to consider, when you’ve got a Decimal, or Double value which you want to convert to an Int, what is your intention?

If your value is something like 5.673 and you want to change this to Int, what do you expect to see?

At a quick glance you would expect it to round the value to the closest integer number, thus 6. But that is not the way conversions are normally set up. The default way most programming languages do conversions from a Double to an Int is called Type-casting, and it will just truncate the decimal value and give you back an answer of 5. In Linx if you set the value from a Double into an Int you will get this same behaviour.

However, if you are busy with numbers and actually requires Linx to round the decimal to the closest number, you can do this by explicitly converting the Double’s value to an Int value by using the ToInt64() function.

Double.ToInt64()

In this case, if your Double was 2.74 you will get an Int of 3. Or if your Double was 6.2 you will get an Int of 6.