andrisp Posted March 15, 2006 Report Share Posted March 15, 2006 Šeit ir kods - http://paste.php.lv/3448 Tiek paņemts skaitlis 2.8 (0.028 * 100) un noapaļots ar fju round(2.8, 2), kas, protams, atgriež to pašu - 2.8, bet nez kāpēc vēlāk pie pārbaudes vai sākumvērtība ir vienāda ar beigu vērtību, tiek izpildīta tā koda daļa, kas paredzēta, ja šīs vērtības nav vienādas. Bet viņas ir ! Pat tipi ir vienādi. Esmu pilnīgi un galīgi apjucis. Palīdziet. Link to comment Share on other sites More sharing options...
Blitz Posted March 15, 2006 Report Share Posted March 15, 2006 ieliec if ("$buu" == "$y") man norm aizgaja Link to comment Share on other sites More sharing options...
andrisp Posted March 15, 2006 Author Report Share Posted March 15, 2006 (edited) Nu it kā jā, bet nevarētu teikt, ka problēma ir atrisināta. Ā, un vēl, izmainām šādi, un viss iet: <? $cena100gb = custom_round(2.80, 2); function custom_round($buu, $p=2) { $y = 0; if(is_numeric($buu)) { $y = round($buu, $p); if ($buu == $y) { return $buu; } else { return '<acronym title="'.$buu.'">~'.$y.'</acronym>'; } } else { return false; } } echo $cena100gb; ?> Nesaprotu :/ Edited March 15, 2006 by andrisp Link to comment Share on other sites More sharing options...
v3rb0 Posted March 15, 2006 Report Share Posted March 15, 2006 ar floatiem tā ir function float_equal($f1, $f2){ return ($f1 > $f2) ? (false) : (!($f1 < $f2));} palasīties vairāk te: http://lv.php.net/operators.comparison Link to comment Share on other sites More sharing options...
Blitz Posted March 15, 2006 Report Share Posted March 15, 2006 I ended up having to compare after multiplying by 10, rounding, and then dividing by 10... rediculous, but sadly the only way I could find to reliably do it. The round seemed to remove the break in the float... Kas tad floatam nak par brake? Link to comment Share on other sites More sharing options...
v3rb0 Posted March 15, 2006 Report Share Posted March 15, 2006 man liekas ka ar break tur domāts gļuks. Link to comment Share on other sites More sharing options...
bubu Posted March 15, 2006 Report Share Posted March 15, 2006 Floatus nekad nepārbauda uz precīzu vienādību dēļ to attēlojuma īpatnībām. Tos parasti uz vienādību salīdzina šādi: function isFloatsEqual($f1, $f2) { return abs($f1-$f2)<1e-6; } Link to comment Share on other sites More sharing options...
Recommended Posts