search
HomeBackend DevelopmentPHP ProblemWhat is the usage of bcsub in php

In PHP, the bcsub() function is used to subtract an arbitrary precision number from another function that accepts two arbitrary precision numbers as strings and scales the result to the specified precision. Then return the subtraction of two numbers, the syntax is "bcsub($num_str1,$num_str2,$scaleVal)".

What is the usage of bcsub in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

What is the usage of bcsub in php

The bcsub() function in PHP is a built-in function used to subtract an arbitrary precision number from another function. This function accepts two arbitrary-precision numbers as strings and returns the subtraction of the two numbers after scaling the result to the specified precision.

Usage:

string bcsub ( $num_str1, $num_str2, $scaleVal)

Parameters: This function accepts three parameters as shown in the above syntax and explained below:

$num_str1: This parameter is a string Type that represents the left operand or one of the two numbers we want to subtract. This parameter is required.

$num_str2: This parameter is of type string and represents the right operand or one of the two numbers we want to subtract. This parameter is required.

$scaleVal: This parameter is of type int and is optional. This parameter tells the number of digits that will appear after the decimal point in the addition result. The default value is zero.

Return value: This function returns the subtraction of two numbers $num_str1 and $num_str2 in string form.

Example:

Input:  $num_str1 = 11.222, $num_str2 = 3
Output: 14
Since the parameter $scaleVal is not specified so
no digits after decimal is appeared in the 
result after subtraction.
Input:  $num_str1 = 11.222, $num_str2 = 3, $scaleVal = 4
Output: 8.2220

The following example program is intended to illustrate the bcsub() function in PHP:

Program 1:

<?php 
// PHP program to illustrate bcsub() function 
   
// input numbers with arbitrary precision 
$num_str1 = "11.222"; 
$num_str2 = "3"; 
   
// calculates the subtraction of 
// the two numbers when $scaleVal is 
// not specified 
$res = bcsub($num_str1, $num_str2); 
  
echo $res; 
   
?>

Output:

8

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the usage of bcsub in php. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment