Perl int 函式



說明

此函式返回 EXPR 的整數元素,如果省略則返回 $_。 int 函式不進行舍入。如果你希望舍入值為整數,你應當使用 sprintf。

語法

以下為此函式的簡單語法 ——

int EXPR

int

返回值

此函式返回 EXPR 的整數部分。

範例

以下為展示其基本用法示例程式碼 ——

#!/usr/bin/perl

$int_val = int( 6.23930 );
print"Integer value is $int_val\n";

$int_val = int( -6.23930 );
print"Integer value is $int_val\n";

$int_val = int( 10 / 3 );
print"Integer value is $int_val\n";

當執行以上程式碼時,它產生以下結果 ——

Integer value is 6
Integer value is -6
Integer value is 3
perl_function_references.htm
廣告
© . All rights reserved.