douminfu8033 2011-03-01 23:47
浏览 110
已采纳

php sqrt函数返回一个整数?

I'm creating a simple PHP program that does an action if (and only if) three random numbers compute to an integer. The random numbers are all integers, created with the rand() function. Without going into the specific details of the computation, the important thing (in terms of my problem) is that it includes the taking of a square root. Not being a very experienced PHP coder, the only square root function I know is sqrt(). The problem is, sqrt() returns a float, even when the input is an integer and output is exact. I briefly thought about converting the output to an integer (using something like intval(), but that won't work because that will convert all outputs to integers, making the test useless! Any ideas on how to do this? Thanks,

  • 写回答

5条回答 默认 最新

  • doucai6663 2011-03-01 23:52
    关注

    If you just want to determine if it is a perfect square, just determine if the

    intval(result) * intval(result) == originalValue
    

    I don't know the php version of those functions, but perhaps you do? :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了