当前位置:网站首页>「PHP基础知识」输出圆周率的近似值
「PHP基础知识」输出圆周率的近似值
2022-07-29 02:58:00 【夜晚回家】
功能要求
浮点数的表示,使用四种方法输出圆周率(π=3.1415926)的近似值:①使用pi()函数;②使用M_PI常量;③使用标准格式;④使用科学计数法。
实例代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>输出圆周率的近似值</title>
</head>
<body>
<?php
echo '圆周率的4种书写方法:<p>';
echo '第一种:pi() = '. pi() .'<br />'; # 使用pi()函数
echo '第二种:M_PI = '.M_PI.'<br />'; # 使用常量M_PI
echo '第三种:3.14159265359 = '. 3.14159265359 .'<br />'; # 标准格式
echo '第四种:314159265359E-11 = '. 314159265359E-11 .'<br />'; # 科学计数法
?>
</body>运行结果
知识说明
浮点数据类型也称为浮点数、双精度数或实数,可以用来存储数字,也可以保存小数。它提供的精度比整数大很多。浮点型数据默认有两种书写格式:
一种是标准格式:
3.1415
-35.8
一种是科学计数法格式:
3.58E1
849.72E-3
注意:浮点型的数值只是一个近似值,所以要尽量避免浮点型数值之间比较大小,因为最后的结果是不准确的。
pi():是一个函数,返回圆周率PI的近似值。
M_PI:是一个常量,显示圆周率PI的近似值。
边栏推荐
- What is SOA (Service Oriented Architecture)?
- Li Shuo, vice president of Baidu: it's a good thing that China's labor costs rise with the support of digital technology
- OWT server source code analysis (4) -- video module analysis of mixer out
- Zone --- line segment tree lazy marking board sub problem
- kubernetes-1.24.x 特性
- 2022-07-28 第四小组 修身课 学习笔记(every day)
- Day 5 experiment
- Restfulapi - C - add header username and password authentication
- CentOS install mysql8
- Summary of classic problems in Flink production environment
猜你喜欢

Verilog's time system tasks - $time, $stime, $realtime

2022-07-28 第四小组 修身课 学习笔记(every day)

2.nodejs--路径(_dirname,_filname)、url网址、querystring模块、mime模块、各种路径(相对路径)、网页的加载(面试题*)

Weekly recommended short videos: how to make product development more effective?

Day 10 notes

向DataFrame中的特定位置添加一行

Idea replaces the contents of all files

Thirty years of MPEG audio coding

创客教育的起源和内涵的基本理念

JVM基础入门篇一(内存结构)
随机推荐
向DataFrame中的特定位置添加一行
Why did I choose the test when the development salary was high?
Algorithm --- paint the house (kotlin)
codeforces每日5题(均1500)-第二十五天
MYSQL入门与进阶(十四)
Object转String的几种方法
Zone --- line segment tree lazy marking board sub problem
cuda-gdb提示:/tmp/tmpxft_***.cudafe1.stub.c: No such file or directory.
会议OA项目之我的审批功能
13_ue4进阶_蒙太奇动画实现一边走一边攻击
创客教育的起源和内涵的基本理念
三子棋(玩家+电脑)
Confusion matrix learning notes
[NPM error] - NPM err code eresolve and NPM err eresolve could not resolve problems
2022-07-28 第四小组 修身课 学习笔记(every day)
vasp计算任务报错:M_divide:can not subdivide 8 nodes by 6
服务器运行管理制度
[QNX Hypervisor 2.2用户手册]9.11 ram(更新中)
04 | 后台登录:基于账号密码的登录方式(上)
《QA离业务代码能有多近?》通过codediff直接暴露缺陷