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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:26:06+00:00 2026-05-29T09:26:06+00:00

I am currently trying to split one value with percentage column. But as most

  • 0

I am currently trying to split one value with percentage column. But as most of percentages values are 1/3, I am not able to get aboslute 100% with two decimal points in the value. For example:

Product    Supplier      percentage         totalvalue        customer_split
                         decimal(15,14)   (decimal(18,2)       decimal(18,2)
--------   --------     ------------     ---------------  ---------------
Product1    Supplier1    0.33            10.00                3.33
Product1    Supplier2    0.33            10.00                3.33
Product1    Supplier3    0.33            10.00                3.33

So, here we are missing 0.01 in the value column and suppliers would like to put this missing 0.01 value against any one of the supplier randomly. I have been trying to get this done in a two sets of SQLs with temporary tables, but is there any simple way of doing this. If possible how can I get 0.34 in the percentage column itself for one of the above rows? 0.01 is negligible value, but when the value column is 1000000000 it is significant.

  • 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-29T09:26:07+00:00Added an answer on May 29, 2026 at 9:26 am

    It sounds like you’re doing some type of “allocation” here. This is a common problem any time you are trying to allocate something from a higher granulartiy to a lower granularity, and you need to be able to re-aggregate to the total value correctly.

    This becomes a much bigger problem when dealing with larger fractions.

    For example, if I try to divide a total value of, say $55.30 by eight, I get a decimal value of $6.9125 for each of the eight buckets. Should I round one to $6.92 and the rest to $6.91? If I do, I will lose a cent. I would have to round one to $6.93 and the others to $6.91. This gets worse as you add more buckets to divide by.

    In addition, when you start to round, you introduce problems like “Should 33.339 be rounded to 33.34 or 33.33?”

    If your business logic is such that you just want to take whatever remainder beyond 2 significant digits may exist and add it to one of the dollar values “randomly” so you don’t lose any cents, @Diego is on the right track with this.

    Doing it in pure SQL is a bit more difficult. For starters, your percentage isn’t 1/3, it’s .33, which will yield a total value of 9.9, not 10. I would either store this as a ratio or as a high-precision decimal field (.33333333333333).

    P    S    PCT           Total  
    --   --   ------------  ------  
    P1   S1   .33333333333  10.00   
    P2   S2   .33333333333  10.00   
    P3   S3   .33333333333  10.00   
    
    
    SELECT 
       BaseTable.P, BaseTable.S, 
       CASE WHEN BaseTable.S = TotalTable.MinS 
          THEN BaseTable.BaseAllocatedValue + TotalTable.Remainder
          ELSE BaseTable.BaseAllocatedValue
       END As AllocatedValue
    FROM
    (SELECT
       P, S, FLOOR((PCT * Total * 100)) / 100 as BaseAllocatedValue,
       FROM dataTable) BaseTable
    INNER JOIN
    (SELECT
       P, MIN(S) AS MinS,
       SUM((PCT * Total) - FLOOR((PCT * Total * 100)) / 100) as Remainder,
    FROM dataTable
    GROUP BY P) as TotalTable
    ON (BaseTable.P = TotalTable.P)
    

    It appears your calculation is an equal distribution based on the total number of products per supplier. If it is, it may be advantageous to remove the percentage and instead just store the count of items per supplier in the table.

    If it is also possible to store a flag indicating the row that should get the remainder value applied to it, you could assign based on that flag instead of randomly.

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

Sidebar

Related Questions

I'm currently trying to get into the Java EE development with the Spring framework.
I'm trying to get a block of code down to one line. I need
Trying to get data in the most efficient way possible for some reports, using
I'm currently trying to most efficiently do an in-place multiplication of an array of
I'm trying to compare two millisecond values in Java. One from a calendar, and
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying to read in an XML file, make some minor changes (alter
I'm currently trying out db4o (the java version) and I pretty much like what
I'm currently trying to build a personal website to create a presence on the
I'm currently trying to port a SIP stack library (pjSIP) to the PSP Console

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.