search
HomeBackend DevelopmentPHP ProblemHow to implement addition, subtraction, multiplication and division in php function

How to implement addition, subtraction, multiplication and division in php function

Oct 19, 2022 am 09:53 AM
phpAddition, subtraction, multiplication and division

How to implement addition, subtraction, multiplication and division by PHP functions: 1. bcadd function, used for addition calculation of two arbitrary precision numbers, the syntax is "bcadd($num1, $num2, $scale)"; 2. bcsub Function, used for subtraction of two arbitrary precision numbers, the syntax is "bcsub($num1, $num2, $scale)"; 3. bcmul function, used for multiplication of two arbitrary precision numbers; 4. bcdiv function, used for Computes the division of two arbitrary-precision numbers.

How to implement addition, subtraction, multiplication and division in php function

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

How do PHP functions implement addition, subtraction, multiplication and division?

Example

$a = 1; $b = 3 ;$c = 2.3
$a *$b *$c 的结果可能变成 6.8999999999999995

bcadd — Addition of two arbitrary-precision numbers

//对 $num1 和 $num2 求和。
bcadd($num1, $num2, $scale)
//参数
//$num1
//左操作数,字符串类型。
//$num2
//右操作数,字符串类型。
//$scale
//设置结果中小数点后的小数位数。如果未设置,则默认为 0。
//返回值
//以字符串返回两个操作数求和之后的结果。

bcsub — Subtraction of two arbitrary-precision numbers

//$num1 减去 $num2。
bcsub($num1, $num2, $scale)
//参数
//$num1
//字符串类型的左操作数。
//$num2
//字符串类型的右操作数。
//$scale
//此可选参数用于设置结果中小数点后的小数位数。如果未设置,则默认为 0。
//返回值
//以 string 类型返回减法之后的结果。

bcmul — Multiplication calculation of two arbitrary-precision numbers

//≈num1 乘以 $num2。
bcmul($num1, $num2, $scale)
//参数
//$num1
//字符串类型的左操作数。
//$num2
//字符串类型的右操作数。
//$scale
//此可选参数用于设置结果中小数点后的小数位数。如果未设置,则默认为 0。
//返回值
//返回字符串类型的结果。

bcdiv — Division calculation of two arbitrary-precision numbers

//$num1 除以 $num2。
bcdiv($num1, $num2, $scale)
//参数
//$num1
//被除数,字符串类型。
//$num2
//除数,字符串类型。
//$scale
//此可选参数用于设置结果中小数点后的小数位数。如果未设置,则默认为 0。
//返回值
//返回字符串类型的结果。如果 $num2 是 0 结果为 null。

Recommended study: "PHP Video Tutorial

The above is the detailed content of How to implement addition, subtraction, multiplication and division in php function. 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

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools