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 7944107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:27:38+00:00 2026-06-04T00:27:38+00:00

Can anyone explain the below output in PHP? $num1 = (1.65 – 1.00); echo

  • 0

Can anyone explain the below output in PHP?

$num1 = (1.65 - 1.00);
echo "<br><br>num1 = " . $num1;   // Output: int = 0.65

$num_int1 = $num1 * 100;
echo "<br><br>int = " . $num_int1;   // Output: int = 65

$num_int2 = (int) $num_int1;
echo "<br><br>int = " . $num_int2;   // Output: int = 64

Why $num_int2 is 64?

Thanks for help.

  • 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-06-04T00:27:40+00:00Added an answer on June 4, 2026 at 12:27 am

    From an article I wrote for Authorize.Net (in your specific case $num_int1 is a float even if it looks like an integer):

    One plus one equals two, right? How about .2 plus 1.4 times 10? That equals 16, right? Not if you’re doing the math with PHP (or most other programming languages):

    echo floor((0.2 + 1.4) * 10); // Should be 16. But it's 15!
    

    This is due to how floating point numbers are handled internally. They are represented with a fixed number of decimal places and can result in numbers that do not add up quite like you expect. Internally our .2 plus 1.4 times 10 example computes to roughly 15.9999999998 or so. This kind of math is fine when working with numbers that do not have to be precise like percentages. But when working with money precision matters as a penny or a dollar missing here or there adds up quickly and no one likes being on the short end of any missing money.

    The BC Math Solution

    Fortunately PHP offers the BC Math extension which is "for arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision, represented as strings." In other words, you can do precise math with monetary values using this extension. The BC Math extension contains functions that allow you to perform the most common operations with precision including addition, subtraction, multiplication, and division.

    A Better Example

    Here’s the same example as above but using the bcadd() function to do the math for us. It takes three parameters. The first two are the values we wish to add and the third is the number of decimal places we wish to be precise to. Since we’re working with money we’ll set the precision to be two decimal palces.

    echo floor(bcadd('0.2', '1.4', 2) * 10); // It's 16 like we would expect it to be.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone can explain why the lines below appear in the output console at runtime
Can anyone explain the behaviour of the below code. The output of the below
Can anyone explain the following PHP Code ? function get_param($param_name, $param_type = 0) {
Can anyone explain what the following PHP Code does function query($query_string) { if ($query_string
Can anyone explain to me why GetInterfaces() in the below code returns an interface
Can anyone explain: Why the two patterns used below give different results? (answered below)
Can anyone explain why the second example below won't compile? 'Test 2' gives error
A quick question if I may, can anyone explain what I am missing below,
Can anyone explain to me why this code below does not work? #include opencv/cv.h
Can anyone explain the below code can any one give some real time explanation

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.