当前位置:网站首页>How does PHP convert negative numbers to positive integers
How does PHP convert negative numbers to positive integers
2022-04-21 16:17:00 【Billion speed cloud】
php How to turn a negative number into a positive integer
This article mainly explains “php How to turn a negative number into a positive integer ”, Interested friends might as well come and have a look . The method introduced in this paper is simple and fast , Practical . Now let Xiaobian take you to learn “php How to turn a negative number into a positive integer ” Well !
php The method of converting negative numbers to positive integers :1、 Use abs() The function converts a negative number to a positive number , Use intval() The function rounds a positive number , Convert to positive integer , grammar “intval(abs($number))”;2、 utilize “~” The bitwise operator negates a negative number and adds one , grammar “~$number + 1”.

The operating environment of this tutorial :windows7 System 、PHP7.1 edition 、DELL G3 The computer
php The method of converting negative numbers to positive integers
Method 1: Use abs() and intval() function
abs() The function converts a negative number to a positive number
intval() The function rounds a positive number , Convert to positive integer
Implementation code :
<?php$number=-12.35;var_dump($number);$result =intval(abs($number));var_dump($result);?>

Method 2: utilize “~” The bitwise operator negates a negative number and adds one
<?phpfunction plus_minus_conversion($number = 0){ echo ~$number + 1;}echo plus_minus_conversion(-100.58);?>

explain :
Take the positive number and add one to the negative number , Get the complement of a negative number , Negative numbers are stored in memory in the form of complement , When the complement is converted to the original code, it is the negative number corresponding to the positive number
Negative numbers take the inverse and add one , Get a complement , But the complement of a positive number is the same as the original code
Be careful : Negation and negation are two different concepts , All operations are in the form of complement , Because there are negative numbers involved
Here we are , I'm sure you're right “php How to turn a negative number into a positive integer ” Have a deeper understanding of , You might as well put it into practice ! This is the Yisu cloud website , For more relevant contents, you can enter the relevant channels for inquiry , Pay attention to our , Continue to learn !
版权声明
本文为[Billion speed cloud]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211611205994.html
边栏推荐
- 确定还不来看看?这样管理你的代码库既方便又省心
- How does infotnews memes, myths and NFT build cultural identity?
- Yunna: is the asset management system of large medical equipment expensive? Main contents of hospital asset management
- 云呐:医院固定资产管理存在的问题及原因,资产管理系统的实施
- Must brush the simulated question bank and answers of the latest eight members of Chongqing in 2022
- The conflict between Russia and Ukraine raised concerns. The five eye network security department suggested that allies strengthen infrastructure protection measures
- ABAP string function list
- 云呐:大型医疗设备资产管理系统贵吗?医院资产管理的主要内容
- AT2293 [AGC009D] Uninity(贪心、状压)
- Burp 一个简易的tp5-rce被动扫描插件
猜你喜欢
随机推荐
Solution to the problem of file damage caused by forced shutdown and power failure during nodejs FS readfilesync
Root unlock problem
Case of kingbasees v8r3 cluster deleting data nodes online in Jincang database
IOS development interview strategy (KVO, KVC, multithreading, lock, runloop, timer)
Sharkteam releases quarterly report on security situational awareness of Q1 smart contract in 2022
PowerShell blog directory
SQL--数据库的操作(DDL,DML,DQL)+使用命令查看当前数据库的存储位置(数据库版本查询)
一文读懂PlatoFarm新经济模型以及生态进展
[Android, kotlin] teaches you to write a weak reference handler tool to avoid memory leakage
R语言ggplot2可视化散点图(scatter plot)、并基于组合规则高亮(highlight)指定的数据点、设置数据点的大小(size)、数据点的色彩(color)
【2023校招刷題】華為性格測評(綜合測評)戰略指南
全国查询水电气费免费接口(一)
Function stack frame creation and destruction (understand)
Burp is a simple TP5 rce passive scanning plug-in
微信h5、APP、微信内jsapi支付接口
Qt5.14.2编译mysql
启动Redis的过程
Assembly language programming: design and debugging of input character type statistics in modular programming
Data processing input box section
Dry goods | solve the common pain points of APP automation test (pop-up frame and home page start loading to complete judgment processing)









