1
2
3
4
5
6
$ round_to_5.pl
VAL: -2.400000 EXP: 0.000000 RES: 0.000000
VAL: -8.300000 EXP: -10.000000 RES: -10.000000
VAL: 7.100000 EXP: 5.000000 RES: 5.000000
VAL: -2.600000 EXP: -5.000000 RES: -5.000000
VAL: 8.400000 EXP: 10.000000 RES: 10.000000
Runden(Value / Schrittweite) * Schrittweite;
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/perl use strict; use warnings; use Math::Round; my @array = (7.1, 8.4, -2.4, -2.6, -8.3, 16.7, -34.8, -12.9, 456.2); foreach( @array ){ print $_." => "; my $new = nearest(5, $_); print $new."\n"; $_ = $new; }