[Solved] Check where number 1 is in decimal number
I wouldn’t rely too much on the approach you posted in your answer. Use the following function instead: function index_of_one($dec) { // maximum precision is 15 $str = str_replace(‘.’,”,sprintf(‘%.15f’, $dec)); $pos = strpos($str, ‘1’); if ($pos === false) { return -1; } return ($pos + 1); } Example: $dec1 = 1.00000000; $dec2 = 0.10000000; $dec3 … Read more