Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6777953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:12:33+00:00 2026-05-26T16:12:33+00:00

For the purpose of the example, var 2 is preset from a database as

  • 0

For the purpose of the example, var 2 is preset from a database as “147.22” type STRING. var 1 is calculated previously in the script and has 147.22 type FLOAT.

Script:

<?

$var1 = (float)$var1;
$var2 = (float)$var2;

var_dump($var1);
var_dump($var2);

if($var1 < $var2) { echo "hello"; }

?>

My expected results would be that the script NOT echo “hello” since the two values are equal in amount and type.

However here is the output I’m getting:

float(197.22)
float(197.22)
hello

If I do not mess with the types and leave the one a float and the other a string, then it still does not work (this is how I got here in the first place).

If i force the values at the time of execution like this:

$var1 = 147.22;
$var2 = 147.22;

var_dump($var1);
var_dump($var2);

if($var1 < $var2) { echo "hello"; }

?>

I get this, (and it works):

float(197.22)
float(197.22)

Notice no “hello”….

Anyone have any clue wth is going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:12:34+00:00Added an answer on May 26, 2026 at 4:12 pm

    If one of the floats is calculated numerically, and one is created from string assignment, they could be different. Try the following:

    $x = 147.22;
    $y = 147.2200000000001;
    printf("%.40f\n", $x);
    printf("%.40f\n", $y);
    var_dump($x);
    var_dump($y);
    var_dump($x < $y);
    

    outputs

    147.2199999999999988631316227838397026062012
    147.2200000000001125499693443998694419860840
    float(147.22)
    float(147.22)
    bool(true)
    

    Cast them to a string with a specified precision for comparison.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the purpose of the colon before a block in Python? Example: if
Using jQuery I get JSON object that extracts one row from database. That row
Do we use OfType() for filtering purpose ? Say example, if i use object[]
For example: [{ id:'our-purpose', title:'Our Purpose', slug:'/our-purpose', backgroundImage:'images/bg-our-purpose.jpg', showInNav:1 }, { id:'our-people', title:'Our People',
This is just for my own curiosity. Isn't the purpose of the var directory
From the Go documentation on method declarations : The receiver type must be of
This is an example from a tutorial about setInterval, but it doesn`t explain it
Consider such code (this is just example not real code): class Foo(url : String)
From the jquery impromptu demo , for my purpose, I added a dropdown list
This is somewhat asp.net MVC related only for example purposes but I was hoping

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.