Home Backend Development PHP Tutorial php是不是有小数部分为.3是不是有漏洞解决方案

php是不是有小数部分为.3是不是有漏洞解决方案

Jun 13, 2016 pm 01:35 PM
boolean var

php是不是有小数部分为.3是不是有漏洞
从html页面获取一个值,数据库读一个值,判断如果他们不相等就干某些事情(!=)当两个数字的小数部分是.3时 居然判断错误;
比如两个数都是54.3或55.3它居然判断 true 应该是false,小数部分为其他时没有问题,比如54.2
有碰到过的没

------解决方案--------------------
没问题啊。。。楼主你的代码有问题或者大脑短路了吧。

PHP code
var_dump(54.3 != 55.3);
//bool(true)
<br><font color="#e78608">------解决方案--------------------</font><br>多次测试,没有发现所说的问题
<br><font color="#e78608">------解决方案--------------------</font><br> 
Copy after login
PHP code

<?php $var['peilv'] = 12.345;
$tempCurPeilv = 234.54;
var_dump($var['peilv'] != $tempCurPeilv);

$var['peilv'] = 55.3;
$tempCurPeilv = 55.3;
var_dump($var['peilv'] != $tempCurPeilv);

echo "<br/>";
echo '$var[\'peilv\']:',$var['peilv'],'$tempCurPeilv:',$tempCurPeilv;
var_dump($var['peilv'] != $tempCurPeilv);
<br><font color="#e78608">------解决方案--------------------</font><br>愚人节吗哈哈<br>
Copy after login
PHP code

boolean true

boolean false


$var['peilv']:55.3$tempCurPeilv:55.3
boolean false
<br><font color="#e78608">------解决方案--------------------</font><br>因为你的比较变成了字符串和浮点数或者其他类型的比较所以结果就出现了你说的异常。 <div class="clear">
                 
              
              
        
            </div>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between Boolean and boolean in Java What is the difference between Boolean and boolean in Java May 05, 2023 pm 07:40 PM

Preface Someone asked, aren’t there only two types of Boolean values: true and false? Why does the attribute he defined have a null value? We should first make it clear that boolean is the basic data type of Java, and Boolean is a class of Java. The boolean type will assign false to the attribute during the "assign zero value" phase. Boolean is a class that will assign null to the object in the "assign zero value" phase. If it is a static property, it will be assigned when the class is loaded. If it is a normal class attribute, the value will be assigned when the object is instantiated. These two points can help you understand the "class loading mechanism" and "object creation process". Class loading mechanism: Loading: Get the binary byte stream of the class based on the full name of the class, and

Convert string to boolean using java's Boolean.valueOf() function Convert string to boolean using java's Boolean.valueOf() function Jul 24, 2023 pm 05:15 PM

Use Java's Boolean.valueOf() function to convert a string to a Boolean value. In Java programming, you often encounter situations where you need to convert a string to a Boolean value. Java provides a convenient way to achieve this requirement, using the Boolean.valueOf() function. This function can convert a Boolean value represented by a string into the corresponding Boolean type. Let's take a closer look at the usage of Boolean.valueOf(). Given a string, we

Let's talk about the differences between var, let and const (code example) Let's talk about the differences between var, let and const (code example) Jan 06, 2023 pm 04:25 PM

This article brings you relevant knowledge about JavaScript. It mainly introduces the differences between var, let and const, as well as the relationship between ECMAScript and JavaScript. Interested friends can take a look at it. I hope Helpful to everyone.

18 Ways to Fix Audio Service Not Responding Issue on Windows 11 18 Ways to Fix Audio Service Not Responding Issue on Windows 11 Jun 05, 2023 pm 10:23 PM

Audio output and input require specific drivers and services to work as expected on Windows 11. These sometimes end up running into errors in the background, causing audio issues like no audio output, missing audio devices, distorted audio, etc. How to Fix Audio Service Not Responding on Windows 11 We recommend you to start with the fixes mentioned below and work your way through the list until you manage to resolve your issue. The audio service may become unresponsive for a number of reasons on Windows 11. This list will help you verify and fix most issues that prevent audio services from responding on Windows 11. Please follow the relevant sections below to help you through the process. Method 1: Restart the audio service. You may encounter

The role and examples of var keyword in PHP The role and examples of var keyword in PHP Jun 28, 2023 pm 08:58 PM

The role and examples of var keyword in PHP In PHP, the var keyword is used to declare a variable. In previous PHP versions, using the var keyword was the idiomatic way to declare member variables, but its use is no longer recommended. However, in some cases, the var keyword is still used. The var keyword is mainly used to declare a local variable, and the variable will automatically be marked as local scope. This means that the variable is only visible within the current block of code and cannot be accessed in other functions or blocks of code. Use var

How to use boolean in java How to use boolean in java Nov 13, 2023 pm 03:34 PM

In Java, boolean is a basic data type with only two possible values: true and false. The boolean type is often used for conditional testing, such as comparison or checking whether a certain condition is met.

Solution to the error AttributeError(\'{0!r} object has no attribute {1!r}\'.format(type(self).__name__, k)) Solution to the error AttributeError(\'{0!r} object has no attribute {1!r}\'.format(type(self).__name__, k)) Feb 29, 2024 pm 06:40 PM

The reason for the error message indicates that in the python code, an object (represented by the self variable) is used, but the object does not have an attribute named k. This may be because the object does not have this property defined, or a type error in the code causes the object to not be of the expected type. How to Fix To resolve this error, you may need to do one or more of the following: Check your code for the error and make sure the object referenced by the self variable has a property named k. Check your code for type errors and make sure the object referenced by the self variable is of the expected type. If the attribute is missing, you need to define this attribute in the class and use tryexcept to get this error. If you are sure that k is an attribute that is not defined in the class, please confirm

What does let var const mean? What does let var const mean? Nov 14, 2023 pm 03:00 PM

llet, var, and const represent block scope variables, function scope variables, and constants respectively. Detailed introduction: 1. let, used to declare a variable in a block scope. A variable declared using let cannot be accessed before it is declared. This is the so-called temporary dead zone; 2. var, used to declare the key to a variable. Word, the declared variable is in function scope or global scope and is not restricted by block-level scope; 3. const, used to declare a constant. Once assigned, the variable cannot be reassigned. The value is after declaration. Cannot be modified etc.

See all articles