Home >Backend Development >PHP Problem >bcsub is a php extension

bcsub is a php extension

藏色散人
藏色散人Original
2021-03-17 11:18:291844browse

bcsub is not an extension of PHP, but a built-in function in PHP. The bcsub function accepts two arbitrary precision numbers as strings and returns the subtraction of the two numbers after scaling the result to the specified precision.

bcsub is a php extension

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

The bcsub() function in PHP is a built-in function , used to subtract one arbitrary-precision number from another. 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.

bcsub — Subtraction of 2 arbitrary-precision numbers

Description

bcsub ( string $left_operand , string $right_operand [, int $scale = int ] ) : string

Subtract the right operand from the left operand.

Parameter

left_operand

The left operand of string type.

right_operand

The right operand of string type.

scale

This optional parameter is used to set the decimal point after the decimal point in the result. Number of decimal places. You can also set a global default number of decimal places for all functions by using bcscale().

Return value

Return the result after subtraction to the string type.

Example

<?php
$a = &#39;1.234&#39;;
$b = &#39;5&#39;;
echo bcsub($a, $b);     // -3
echo bcsub($a, $b, 4);  // -3.7660
?>

Recommended study: " PHP video tutorial

The above is the detailed content of bcsub is a php extension. 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