当前位置:网站首页>Differences between PHP round and sprintf functions
Differences between PHP round and sprintf functions
2022-07-26 23:14:00 【Yard farmer is by my side】
PHP round and sprintf Difference of function
function format_value1($data, $v = 2)
{
return sprintf("%.{$v}f", $data);
}
function format_value2($data, $v = 2)
{
return round($data, $v);
}
$value='343.39';
$lastValue='303.12';
$unit='1.5';
$price = format_value1(($value - $lastValue) * $unit);
// Output is 60.40
$price = format_value2(($value - $lastValue) * $unit);
// Output is 60.41
round Functional ratio sprintf More accurate round The disadvantage is when dealing with integer formatting The return will not be the standard two decimal places It can be used sprintf Just a formatted number
function format_value($data, $v = 2)
{
$data = round($data, $v);
return sprintf("%.{$v}f", $data);
}
边栏推荐
- 8-其他编程语言--记录
- 基于gRPC编写golang简单C2远控
- Is test development development development?
- Restful interface specification
- One fingerprint patent has been declared invalid! Huiding and siliwei both officially responded!
- Apifox--比 Postman 还好用的 API 测试工具
- 面试官问:JS的this指向
- Mate30 series release: how far can Huawei go in reconstructing images?
- 【无标题】
- Huawei atlas900 reveals the secret: it integrates thousands of shengteng 910 chips, and its computing power is comparable to 500000 PCs!
猜你喜欢

Plato Farm有望通过Elephant Swap,进一步向外拓展生态

Calendar documents implemented by several qwidgets

利用Go制作微信机器人(一)发送消息

Network and VPC hands-on experiment

Esmfold: a new breakthrough in protein structure prediction after alphafold2

Hcia-r & s self use notes (23) DHCP
![[hcip] OSPF relationship establishment](/img/19/e03fea44f2908c7b585e7a1f87c075.png)
[hcip] OSPF relationship establishment

【HCIP】OSPF 关系建立

关于 StatefulWidget,你不得不知道的原理和要点!

Do you know the common core types of magnetic ring inductors?
随机推荐
Basic use of gateway
After working for one year, I have some insights (written in 2017)
Apifox -- a better API testing tool than postman
企业如何缓解物联网和工业物联网安全风险
Typescript stage learning
Xinding acquires Ziguang holdings! Wanye enterprise: comprehensive transformation of integrated circuits!
华裔科学家Ashe教授对涉嫌造假的Nature论文的正面回应
Promote the replacement of X86 with arm server chips, and Huawei and Feiteng carry the banner of localization!
Recruit | PostgreSQL database R & D engineers every week, with an annual salary of 60+, high salary for famous enterprises, and challenge yourself!
HCIA-R&S自用笔记(19)VLAN配置及实验、VLAN间路由
逆袭黑马:数据库全栈工程师(DevDBOps)培训,把最好的课程送给您!
New thrust of Moore's law, detailed explanation of Intel Advanced Packaging Technology!
每周招聘|PostgreSQL数据库研发工程师,年薪60+,名企高薪,挑战自我!
Openstack virtual machine network card is renamed cirename0
Hcia-r & s self use notes (23) DHCP
正则表达式与绕过案例复现
[postgresql]postgresqlg use generate_ Series() function completes statistics
2019 biometric forum successfully ended: these ten highlights should not be missed!
蔚来杯2022牛客暑期多校训练营2
PostgreSQL and Navicat: the backbone of the database industry