PHP – 如何使用 bcscale() 函式設定或獲取所有 bc 數學函式的預設精度引數?


在 PHP 中,**bcscale()** 函式用於設定所有 **bc 數學** **函式** 的預設精度引數。此函式為所有後續呼叫不顯式指定精度引數的 bc 數學函式設定預設精度引數。

語法

int bcscale($scale)

引數

**bcscale()** 引數只接受單個引數,並且它是必須的整數型別引數。此引數表示小數點後數字的位數。其預設值為 0。

返回值

**bcscale()** 函式返回舊的精度值。

示例 1

<?php
   // default scale : 5
   bcscale(5);

   // The default scale value as 5
   echo bcadd('107', '6.5596'), "
";    // this is not the same without bcscale()    echo bcadd('107', '6.55957', 1), "
";    // the default scale value as 5    echo bcadd('107', '6.55957'), "
"; ?>

輸出

113.55960 113.5 113.55957

示例 2

<?php
   // set default scale 5
   bcscale(5);

   // set the default scale value as 5
   echo bcadd('107', '6.5596'), "
";    // this is not the same without    bcscale()    echo bcadd('107', '6.55957', 1), "
";    // Changed the default scale value    bcscale(3);    // the default scale value as 5    echo bcadd('107', '6.55957'), "
"; ?>

輸出

113.55960 113.55 113.559

更新於:2021年8月21日

218 次瀏覽

啟動你的職業生涯

完成課程獲得認證

開始學習
廣告