當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP bcscale()用法及代碼示例

bcscale()函數是PHP中的內置函數。它為所有bc數學函數調用設置默認的小數位數參數。當我們在程序中調用函數bcscale()時,在此函數中傳遞的參數將成為默認比例因子,默認情況下為零。

用法:

int bcscale($scale)

參數:該函數接受單個參數$scale,它是int類型,是強製性的。此參數表明所有bc數學函數的函數調用結果中小數點後出現的位數。其默認值為零。


返回值:此函數返回舊的比例值。

以下示例程序旨在說明PHP中的bcscale()函數:

程序1:

<?php 
  
// default scale : 3 
bcscale(3); 
  
// takes the default scale value as 3  
// which is declared at the beginning  
echo bcadd('111', '6.55957'), "\n"; // 16.007 
  
// this is not the same without bcscale() 
echo bcadd('111', '6.55957', 1), "\n"; // 16.007 
  
//  takes the default scale value as 3  
// which is declared at the beginning  
echo bcadd('111', '6.55957'), "\n"?>

輸出:

117.559 
117.5 
117.559

程序2:

<?php 
  
// default scale : 3 
bcscale(5); 
  
// takes the default scale value as 3  
// which is declared at the beginning  
echo bcadd('111', '6.55957'), "\n"; // 16.007 
  
// this is not the same without bcscale() 
echo bcadd('111', '6.55957', 1), "\n"; // 16.007 
  
// default scale value changes 
bcscale(2);  
  
// takes the default scale value as 2 
// which is declared  
echo bcadd('111', '6.55957'), "\n"?>

輸出:

117.55957 
117.5 
117.55

參考:
http://php.net/manual/en/function.bcscale.php



相關用法


注:本文由純淨天空篩選整理自ChetnaAgarwal大神的英文原創作品 PHP | bcscale() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。