Int32.From

語法

Int32.From(
    value as any,
    optional culture as nullable text,
    optional roundingMode as nullable number
) as nullable number

關於

根據指定的 number 傳回 32 位元整數 value 值。 如果指定的 value 為 null,Int32.From 會傳回 null。 如果所指定 value 是在 32 位元整數範圍內的 number 且沒有小數部分,則會傳回 value。 如果數字有小數部分,則會根據指定的四捨五入模式來將數字進行進位。 預設的四捨五入模式為 RoundingMode.ToEven。 如果 value 是任何其他類型,它會先使用 number轉換成 Number.FromText。 如需可用的四捨五入模式,請參閱 Number.Round。 也可以提供選擇性的 culture (例如,"en-US")。

範例 1

取得 number 的 32 位元整數 "4" 值。

使用方式

Int32.From("4")

輸出

4

範例 2

使用 number 以取得 "4.5" 的 32 位元整數 RoundingMode.AwayFromZero 值。

使用方式

Int32.From("4.5", null, RoundingMode.AwayFromZero)

輸出

5