This article is mainly to share with you the PHP floating point type detailed parsing, I hope you have a deeper understanding of the PHP floating-point type.
Floating-point data is a problem of precision.
Var_dump (0.9 = = (1-0.1)) ==>>
Floating point numbers are the ones with decimals, and they are not just numbers. when I use the payment interface, I have encountered the problem of floating point loss. let's take a look at the solution. let's take a look at the following code: $
I have written an article about the floating point number in PHP: you should know about the PHP floating point number (All 'bogg' aboutthefloatinPHP). However, I missed a point at the time, that is, to answer the following Frequently Asked Questions:
This article describes in detail the floating point numbers in php and a small problem about floating point numbers in applications. if you need it, you can refer to PHP as a weak language, this feature requires seamless and transparent implicit
Regular expression matching the leading and trailing spaces: (^/s*) | (/s*$)String.prototype.trim = function (){Return This.replace (/(^/s*) | ( /s*$)/g,);}Use regular expressions to decompose and convert IP addresses:The following is a JavaScript
The filter_validate_float filter uses the value as a floating point number for verification.*/$ Var = 12.3;Var_dump (filter_var ($ var, filter_validate_float ));// Float (1, 12.3)/*Non-negative floating point number (positive floating point number +
Floating Point Number comparison
1. An error occurred while directly comparing links (=)
Floating point numbers can be compared, but some errors may occur due to the difference in precision between different floating point types.
Example 1:
#
Document directory
Float storage Parsing
Floating-point Subtraction
12.0f-11.9f Calculation
This article uses float as an example to explain how to store floating point numbers and How to Lose precision.First, let's take a look:
float f = 12.0
There is a sentence in the PHP manual:Never compare two floating point numbers for equality.
I didn't care too much in the past. I recently fell into the project because of this problem, so I kept it in mind.
The internal processing of floating
The filter_validate_float filter uses the value as a floating point number for verification.*/$ Var = 12.3;
Var_dump (filter_var ($ var, filter_validate_float ));
// Float (1, 12.3)
/*Non-negative floating point number (Positive floating point
Swift Programming Language Learning-annotations, semicolons, integers, floating-point numbers
Note
Note the non-execution text in your code into prompts or notes for future reading. The Swift compiler automatically ignores the comments when
When I was recruiting on campus last time, I asked a few students a question about floating point computing.CodeWhy is the first row returned?FalseAnd both the second and third rows returnTrue.
Console. Writeline ("1.123f + 1.345f = 2.468f? {0
The example in this paper describes the two float (floating-point) comparison methods in PHP. Share to everyone for your reference. Specific as follows:Recently in the development of a contract management system, involving two floating-point
There's a pit ahead.PHP uses subtraction and other operators to calculate floating-point numbers, often unexpected results, especially on the financial data aspects of the calculation, to many engineers caused a lot of trouble. For example, today's
Companies want to adjust the price of products, because do the foreign trade Mall, so the price and international standards. For example, foreign prices show the way is: the identification of the $35.00; $56.2 is identified as: $56.20.
sprintf ("%1\
In printf: If output is in%f format, 8 bytes will be output (scanf input,%f is 4 bytes)When the parameter is in the stack if it is a float type or double directly into the stack 8 bytes, the output and subsequent output is no problemHowever, if the
How does JS determine whether the input is a positive integer, floating point number, and other numeric Functions
1. The following lists some regular expressions that interpret numeric types."^ // D + $" // non-negative integer (positive
Javascript
0.1 + 0.2 Why isn't it equal to 0.3? (correct result: 0.30000000000000004)
0.8 * 7 Why not equal to 5.6? (correct result: 5.6000000000000005)
Php
Var_dump (intval (0.58 * 100));
The correct result is 57, not 58
The curse of floating-point
Javascript
0.1 + 0.2 Why isn't it equal to 0.3? (correct result: 0.30000000000000004)
0.8 * 7 Why not equal to 5.6? (correct result: 5.6000000000000005)
Php
Var_dump (intval (0.58 * 100));
The correct result is 57, not 58
The curse of floating-point
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.