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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:25:22+00:00 2026-05-31T13:25:22+00:00

I have a table with a field’s datatype set to float. the values for

  • 0

I have a table with a field’s datatype set to float. the values for a given set of records should give a sum of 1 and the field in the select does return 1 however, a HAVING clause states otherwise.

Here are the exact values I have in my table and as you can see, this example does the same thing. Why does this sum up to more than 1 ? I am lost!

with example as (
    SELECT 'Code' as Code, cast(0.462 as float) as perc
    UNION ALL
    SELECT 'Code' as Code, cast(0.116 as float) as perc
    UNION ALL
    SELECT 'Code' as Code, cast(0.181 as float) as perc
    UNION ALL
    SELECT 'Code' as Code, cast(0.053 as float) as perc
    UNION ALL
    SELECT 'Code' as Code, cast(0.188 as float) as perc
)

SELECT 
    Code,
    SUM(perc)
FROM
    example
GROUP BY Code
HAVING SUM(perc) > 1
  • 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-31T13:25:23+00:00Added an answer on May 31, 2026 at 1:25 pm

    I think you mis-understand floats. I don’t mean that in a patronising way, most people mis-understand floats, unfortunately.

    Floating point numbers are able to “re-scale” themselves. Being able to hold huge numbers, or tiny numbers, all in the same data-type. That doesn’t mean they are ‘infinitely precise’. It just means that they have an extreme range that they can cover. They do, however, pay a price for that flexibility. They have a rounding error due to them being binary approximations of decimal numbers.

    If you want to know more about it, there is plenty on the web. It messes with people’s heads at first, but once you understand you’ll be better, safer and wiser for it.

    So, for your case, if you want to preserve the exact value, don’t use a floating point data type. Use a fixed point data type instead.

    If you change from FLOAT to something like DECIMAL(9,4) then you won’t get the rounding errors associated with floating point numbers.

    You won’t be able to store 0.12345 in it though, you’d need to specify DECIMAL(9,5) for that. But you will be always guaranteed that any number you can store in it will be stored exactly, and not approximately.

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

Sidebar

Related Questions

I have a mysql table field set as time type which stores data in
I have a table with ' id ' as the primary field and set
I have table invoices with field customer_id and some others fields. I need select
I have a table with one field as name.The values in this fields are
I have a table with a field name BID with its data type set
i have table (MEN) with 900,000 records. in this table i have field IP
I have a database table which records all field changes in all database tables
I have a table with values (field valore): CREATE TABLE values ( questionario_id INT(10)
I have the following code: $sql = SELECT table.field, table2.field2 FROM table, table2; $stmt
If I have a table field named 'description', what would be the SQL (using

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.