473,387 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Distribute numbers evenly across records

Hi all,

I am a newby to this forum. I am making modifications to an existing database. The structure is basicall one primary record in a main table with many associated records in a second table. The associated records has a field in it called hours and is formated as a number. I need to update this field based on criteria in a text box which is also a number. In all the the idea is to take the text box number which represent cuts to the hours field but these cuts need to be spread over all of the records in the same ratio as the original hours. Here goes... example: 5 records have a total of 21 hours. each record obviously hs a different "hours" number. Record 1 has 3; record 2 has 1; etc until all five add to 21. If I wanted to cut the total of 21 hours by 11 hours I have the following formula in an update query: 11divided by 21 * the number of hours inf the hours field. It works great until I have to round the numbers. Sometimes (more often than not) the calculation does not work out evenly and I always end up not getting to the new number, (21 to 10). Every rounding combination that I have tried does not tie up the left over fraction of numbers. Hopefully I have explained this enough for someone to understand. Please if anyone has any ideas, please let me know how to control the calulation so that I end up with spreading these "cut hours" across all the records in the same percentage of the original.

Thanks
Kevin
Aug 21 '07 #1
1 2858
Jim Doherty
897 Expert 512MB
Hi all,

I am a newby to this forum. I am making modifications to an existing database. The structure is basicall one primary record in a main table with many associated records in a second table. The associated records has a field in it called hours and is formated as a number. I need to update this field based on criteria in a text box which is also a number. In all the the idea is to take the text box number which represent cuts to the hours field but these cuts need to be spread over all of the records in the same ratio as the original hours. Here goes... example: 5 records have a total of 21 hours. each record obviously hs a different "hours" number. Record 1 has 3; record 2 has 1; etc until all five add to 21. If I wanted to cut the total of 21 hours by 11 hours I have the following formula in an update query: 11divided by 21 * the number of hours inf the hours field. It works great until I have to round the numbers. Sometimes (more often than not) the calculation does not work out evenly and I always end up not getting to the new number, (21 to 10). Every rounding combination that I have tried does not tie up the left over fraction of numbers. Hopefully I have explained this enough for someone to understand. Please if anyone has any ideas, please let me know how to control the calulation so that I end up with spreading these "cut hours" across all the records in the same percentage of the original.

Thanks
Kevin
Kevin

What is the data type of the number you are working with? look at the DECIMAL datatype which will give you the precison you seek. In addition you might want to look at creating a formula in a 'query' as a column so that the return values can be 'calculated' rather than stored?

Jim
Aug 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: | last post by:
I have to write a program that displays all of the perfect numbers less than 1000. I know I need 2 for loops and at least one if statement. What I need to know is, is there any method in Java to...
2
by: webmaker | last post by:
I have a table that is a menu containing 10 items horizontally. I want it to be able to stretch across the screen sizing itself appropriately. I have each item in a separate table cell and I was...
24
by: Stavros Christoforou | last post by:
Hello everyone, I was wondering if someone could help me with an issue I have in C++. I want to select random points within the volume of a sphere. I know how to get random numbers using srand()...
6
by: Damon Grieves | last post by:
Hi I just want to be sure I understand how the Access client works. If I have an Access back end with a million records on a server and an Access client. If the client is installed on the users pc...
5
by: sparks | last post by:
We have a database with 1600+ records in it. They are linked across 7 tables by an ID type autonumber. Now we want(not I want LOL) to remove the first 1200 records no problem but they also...
0
by: PromisedOyster | last post by:
I have an ASP menu (.NET 2.0) that is populated from the sitemap (see below for definition). However, I notice that the elements in the menu are not spaced evenly across. Is there any way to...
5
by: Hopp Family | last post by:
Here's the problem. I want to display a known number of images, evenly spaced out across the width of a div. (The images are not all the same width; the centers should be evenly spaced.) The div...
6
by: devoreband | last post by:
hey i wrote all my code but i need to print out only the even numbers so is there any predefined function i can use or what can structure i should be following? ........ 16 for(int r = 0;...
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.