Thread prüfen auf ganze zahl mit perl (36 answers)
Opened by skontox at 2009-11-22 00:33

bianca
 2009-11-27 17:05
#128648 #128648
User since
2009-09-13
6977 Artikel
BenutzerIn

user image
Von kaputt hab ich nicht gesprochen sondern von merkwürdig.

Und merkwürdig finde ich
Code: (dl )
You should not use this function for rounding: one because it truncates towards 0, and two because machine representations of floating point numbers can sometimes produce counterintuitive results. For example, "int(-6.725/0.025)" produces -268 rather than the correct -269; that's because it's really more like -268.99999999999994315658 instead.

allemal. Auch wenn das vielleicht nichts primär mit Perl's int() zu tun haben mag.

Besonders geil aber finde ich diesen hier:
Code: (dl )
Usually, the "sprintf", "printf", or the "POSIX::floor" and "POSIX::ceil" functions will serve you better than will int().


Denn
Code (perl): (dl )
print "SPRINTF : >" . sprintf("%d",0.57 * 100) . "<\n";
finde ich nicht wirklich "better than will int()", weil es den gleichen Stuß liefert wie
Code (perl): (dl )
print "INT     : >" . int(.57 * 100) . "<\n";
und
Code (perl): (dl )
print "FLOOR   : >" . floor(0.57 * 100) . "<\n";
:))

Aber das sind ja alte Hüte, wir wissen es ja und können damit leben.
Zumindest funktioniert ein
Code (perl): (dl )
if (int (.57*100) eq 57) 

nicht wirklich, obwohl es doch eigentlich nett wäre :)
Edit: Und das ist, was ich merkwürdig oder besser ausgedrückt schade finde.
Last edited: 2009-11-27 17:07:55 +0100 (CET)
10 print "Hallo"
20 goto 10

View full thread prüfen auf ganze zahl mit perl