CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [abs52] Number Comparison: Edit Log

Veteran / Moderator

Mar 20, 2018, 10:16 AM

Views: 9617
Re: [abs52] Number Comparison

You can't test floating point numbers for equality. You need to convert them to integers then test.

Here is one method, there are other methods to do the comparison.


use warnings;
use strict;

my $hello = 384.99;
my $hello2 = 384.128;

if ( $hello * 1000 >= $hello2 * 1000) {
print "$hello newer than or same as wanted $hello2\n";
else {
print "$hello older than wanted $hello2\n";

(This post was edited by FishMonger on Mar 20, 2018, 10:17 AM)

Edit Log:
Post edited by FishMonger (Veteran) on Mar 20, 2018, 10:17 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives