in reply to number comparison with a twist
#!/usr/bin/perl use strict; use warnings; foreach my $y (qw(19.990 19.9 19. 19.559 19.00 19.34776454540000)) { my $x =$y."00"; # at least 2 digits past the decimal $x =~ s/(\d+)(\.)(\d{2})(\d+)?/$1$3/; print "result: $y => $x\n"; } __END__ result: 19.990 => 1999 result: 19.9 => 1990 result: 19. => 1900 result: 19.559 => 1955 result: 19.00 => 1900 result: 19.34776454540000 => 1934
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: number comparison with a twist
by anotherguest (Novice) on Mar 03, 2020 at 09:06 UTC | |
by pryrt (Abbot) on Mar 03, 2020 at 14:41 UTC | |
by anotherguest (Novice) on Mar 05, 2020 at 13:39 UTC | |
by pryrt (Abbot) on Mar 05, 2020 at 15:09 UTC | |
by Marshall (Canon) on Mar 05, 2020 at 09:30 UTC | |
by anotherguest (Novice) on Mar 05, 2020 at 13:32 UTC |