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

类型转换指数数字到int或float

The following code:

echo (int) "2e2";
echo (int) 2e2;
echo (float) "2e2";

outputs

2
200
200

.. and i have no idea why. Thanks.

"2e2" is scientific notation, meaning 2*102 == 200.

  1. In your first example, parsing the string as an int reads only digits up to the first non-digit (so it ignores the e).
  2. The PHP parser treats 2e2 as a float literal with value 200.0 and this gives 200 when cast to a int.
  3. Parsing the string as a float understands the notation and gives the expected result of 200.

近期文章

  • 如何用python画双向条形图
  • win10的环境 下安装python 后继续安装 homeassistant 出现错误。无法解决帮助
  • 台式机安装linux无法启动怎么解决
  • Failed to load resource: the server responded with a status of 404 ()
  • 宝塔云建站后网站无法访问
  • python中用open打开文件遇到了报错,求个解释
  • clickhouse-backup备份不到数据
  • 怎么让虚拟机的网卡和真实设备连接?能不能实现?
  • php访问json中的属性
  • SQL中表嵌套表的数据结构如何去实现
  • java能不能合并相邻的经纬度点
  • Bootstrap下载
  • win11下ubuntu的EFI分区删不掉
  • mysql安装提示应用程序无法正常启动(0xc000007b,如何解决?
  • 学习php,该从何下手?
  • 请教各位工友,如何解决
  • Qt QListWidget和QTabWidget
  • spring注解@Bean相关问题
  • 使用__get或类似方法访问Array类型的类成员变量
  • python中import使用方法

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华