Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

PHP | bcscale() Function

  • Last Updated : 19 Apr, 2018

The bcscale() function is an inbuilt function in PHP. It sets the default scale parameters for all bc math function calls. When we call the function bcscale() in a program, the parameter passed in this function thus becomes the default scale factor which by default is zero.

Syntax:

int bcscale($scale)

Parameters: This function accepts a single parameter $scale and is of int type and is mandatory. This parameter tells the number of digits that will appear after the decimal in the result of function call of all bc math functions. Its default value is zero.

Return Value: This function returns the old scale value.

Below programs illustrate the bcscale() function in PHP :

Program 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"
?>

Output:

117.559 
117.5 
117.559

Program 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"
?>

Output:

117.55957 
117.5 
117.55

Reference:
http://php.net/manual/en/function.bcscale.php


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!