Saturday, September 28, 2024
Google search engine
HomeLanguagesPHP | bcscale() Function

PHP | bcscale() Function

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

Last Updated :
19 Apr, 2018
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments