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

  • SEARCH
  • Home
  • 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 8276625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:25:35+00:00 2026-06-08T08:25:35+00:00

Thanks for checking this out people. I’m learning PHP from PHP for Absolute Beginners

  • 0

Thanks for checking this out people.
I’m learning PHP from “PHP for Absolute Beginners” book but can’t figure why I get the wrong answer from the code below:

<?php
$amt1=2.55;
$amt2=3.55;
$total= $amt1 + $amt2;
echo'<br/>The total is $'. $total;
printf('<br/>The total is %.21f', $total);
?>

I get 6.099999999999644729 not 6.1000… (just imagine 20 zeros)
Using Eclipse/XAMP/MAC OSX Lion How can the computer lie like that- or (more likely) how can I keep it honest by writing better code?

  • 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-08T08:25:36+00:00Added an answer on June 8, 2026 at 8:25 am

    floats have limited precision. floats cannot represent all numbers (one or more of 2.55, 3.55 or 6.10 is not representable precisely). In situations where very high or exact precision is required, floats are the wrong data type. You’re best bet here is probably round.

    (On a technical note, “floats have limited precision” is a bit wrong. What might be more accurate is “floats can only represent some numbers exactly. Some numbers are impossible to represent with exact precision with a float.”)

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

Sidebar

Related Questions

this is probably quite a simple problem, however, I can't figure out how to
Thanks for checking out this Question. I think I've just about scratched through my
thanks for checking this question out. This is my first question here so any
I've been googling for this and checking through the gdb manual but can't seem
I have a PHP website where people can fill out help-tickets. It allows them
Thanks for checking this out: What im doing is reading multiple values like name
Thanks for checking out my problem... I'm having trouble submitting a login form via
I have a project in a repository. People will soon start checking it out,
Greetings everyone and thank you for checking out my post. I am trying to
Thanks for stopping by. this static analyser warning is annoying me here is my

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.