我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

计算精度

Let's say I have a number 10.5. Using PHP, I'd like to format it as 10.50. I know I can use number_format(10.5, 2). But the number of decimal places depends on a value subunit_to_unit, which in this case is equal to 100. If all I know is that subunit_to_unit is 100, how can I format 10.5 as 10.50?

The logarithm of 100 to base 10 is 2. So you can just use log(subunit_to_unit, 10) to get your 2 here. You may want to floor the result, though, in case subunit_to_unit is something like 129.

近期文章

  • 使用php curl中的用户名和密码登录网站
  • SELECT和INSERT不选择
  • 在php中确定一个空数组
  • Laravel 4 - 使用自定义代码自定义auth.basic验证凭据
  • 如何在PHP中使用date_default_timezone_set()函数和+1天
  • array_push覆盖以前创建的对象PHP
  • 有没有办法从SQL查询返回绑定结果?
  • 如何对整个根文件夹进行cookie访问
  • php加倍\字符(打破mysql_real_escape_string,PDO->引用等)[重复]
  • 如何使用Zend 2 url helper添加主机名和协议?
  • PHP preg_replace浏览器和控制台的行为不同
  • 向登录用户显示与匿名用户不同的信息[关闭]
  • 定义多个变量laravel以在if语句中使用
  • 将对象数组打印到HTML数据属性中
  • mysql数据未使用JSON更新
  • 数据库表中的网站设置
  • 搜索功能返回strpos()警告
  • 下降模型关系laravel
  • Laravel Input ::总是返回true
  • PHPUnit的Composer自动加载失败

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华