How to truncate a floating point number up to N decimal places in Prolog?
Is there any built-in tool for this?
How to truncate a floating point number up to N decimal places in Prolog?
Is there any built-in tool for this?
Copyright © 2021 Jogjafile Inc.
Actually, it is easy to define a predicate
truncate/3
in Prolog. Let's say that we want truncate a real numberX
up toN
decimal places and store its result inResult
. Using the mathematical function for truncation in this Wikipedia site, we can define the predicate as follows:I use cut because the two above cases are mutually exclusive.