For example, how many digits do I have (the digits behind the decimal point are not fixed): 1, 155.0552, 122.1963, 0.9631? How can I make the last decimal point of these digits + 1, or-1? For example, in the case of + 1, we hope to get: 1, 155.0562, 122.1973, and 0.9632. For example, I have several numbers (the digits after the decimal point are not fixed ):
1. 155.055
2. 122.196
3. 0.9631
What can I do to make the last decimal point of these numbers + 1, or-1? For example, in the case of + 1, we hope to get:
1. 155.056
2. 122.197
3. 0.9632
Reply content:
For example, I have several numbers (the digits after the decimal point are not fixed ):
1. 155.055
2. 122.196
3. 0.9631
What can I do to make the last decimal point of these numbers + 1, or-1? For example, in the case of + 1, we hope to get:
1. 155.056
2. 122.197
3. 0.9632
$num =12.2346;$tmp = explode('.',$num);$dec = end($tmp);$count = strlen($dec);$p= pow(0.1,$count);$result = $num+$p;echo($result);
Change it to a function, and add some judgment in some places,
Store them as integers, and then store a decimal point.
Because float type still cannot accurately represent 0.1 0.01 0.001... When data is added or deleted multiple times, there will be a cumulative error, or even the addition is the same as the addition.
For example
0.1+0.2 == 0.30000000000000004
$ N = 10.123;
$ Fix = floatval (pow (10, strlen (explode ('.', strval ($ n) [1]);
$ N = ($ n * $ fix + 1)/$ fix;