trunc

用于返回整数部分的 OPL 函数

用途

用于返回整数部分的 OPL 函数。

类型
float

语法

trunc(float f)

描述

返回给定浮点值的整数部分。 您可以通过指定 OPL 名称空间在 IBM ILOG Script 语句内使用此函数:

( Opl.xxx() )

示例

float a=-2.5;
float b=3.5;

float truncofa=trunc(a);
float truncofb=trunc(b);

execute
{
   writeln("trunc(",a,") gives ",truncofa);
   writeln("trunc(",b,") gives ",truncofb); 
}

结果

trunc(-2.5) gives -2
trunc(3.5) gives 3