
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Set or Get Default Scale Parameter for BC Math Functions using bcscale()
In PHP, bcscale() function is used to set the default parameter for all bc math functions. This function sets the default scale parameter for all following calls to the bc math functions that do not explicitly specify a scale parameter.
Syntax
int bcscale($scale)
Parameters
The $bcscale() parameter accepts only a single parameter and it is the mandatory integer type parameter. This parameter shows the number of digits which come after the decimal. Its default value is 0.
Return Value
The $bcscale() function returns the old scale value.
Example 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'), "
"; ?>
Output
113.55960 113.5 113.55957
Example 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'), "
"; ?>
Output
113.55960 113.55 113.559
Advertisements