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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:58:04+00:00 2026-05-11T14:58:04+00:00

I put a check in a script that makes sure a total is correct.

  • 0

I put a check in a script that makes sure a total is correct. What it does is looks at the total as it is stored in the database and then using other variables, calculates what the total should be.

If these two values – the stored total and the calculated total – are not equal, it’s a problem so I want it to send an email alert.

Here’s the snippet of the code I use to do this:

$storedTotal     = $row['total']; # Pulls from a varchar field in the database $calculatedTotal = $subtotal + $tax + $shipping - $deduct;  # Make sure the stored total equals what it should (the calculated total) if($storedTotal != $calculatedTotal) {     # Send an alert     mail('admin@domain.com','Total check fail','Stored total:$storedTotal \n\n Calculated total:$calculatedTotal \n\n'); } 

It seems very simple, however, I repeatedly get emails from it that looks like this:

Stored total:23.40  Calculated total:23.40 

As you can see, the two values appear the same.

Can anyone see any reason why they’re not showing as equal? I’m not using a strict equality check so it shouldn’t be getting tripped up on types.

  • 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. 2026-05-11T14:58:04+00:00Added an answer on May 11, 2026 at 2:58 pm

    Try converting and rounding before you compare them:

    $storedTotal        = round(floatval($storedTotal), 2); $calculatedTotal    = round(floatval($calculatedTotal), 2);  if ($storedTotal != calculatedTotal) { ... 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 94k
  • Answers 94k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've done something like this once. The main source of… May 11, 2026 at 6:51 pm
  • Editorial Team
    Editorial Team added an answer Sharing your connections is the problem. There is no need… May 11, 2026 at 6:51 pm
  • Editorial Team
    Editorial Team added an answer It's possible, they won't migrate. The code still works, it's… May 11, 2026 at 6:51 pm

Related Questions

I'm running a cronjob which needs to write data to a cache. I wanted
I have a few things that I cannot find a good way to perform
How can I find what's hanging all new installations on a Windows box? While
As part of my integration strategy, I have a few SQL scripts that run

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.