473,512 Members | 14,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dividing two numbers

I have spent many hours to solve this problem but no result yet. Your
help will highly be appriciated.

Problem:
Let us say I have two field named as number1 and number2

There are 12 pcs of an item in a carton. when I enter 252 in number1
field and enter 12 in number2 field and run a query with calculated
field as follows:
[Number1}/[Number2] I get 21, which is what I should get.
But when I enter 251 in number1 field and enter 12 in number2 field
and run the same equation I get 20.92. This is not what my client
wants. He wants displayed 20.11. 20 before decimal represents 20
cartons and 11 after decimal represents 11 pcs left in a carton of 12
pc.

Thanking you all in advance
Nov 13 '05 #1
5 9242
If you want to place the full equation in the one field use the following:
Cartons: Int([Number1]/[Number2]) & "." & [Number1] Mod [Number2]
The problem here is that the period is always displayed.

If you want to place the whole cartons in one field and the remainder in
another use the following:
Cartons: Int([Number1]/[Number2])
Remainder: [Number1] Mod [Number2]

Jeff
"Hasanain F. Esmail" <ha*******@yahoo.com> wrote in message
news:27**************************@posting.google.c om...
I have spent many hours to solve this problem but no result yet. Your
help will highly be appriciated.

Problem:
Let us say I have two field named as number1 and number2

There are 12 pcs of an item in a carton. when I enter 252 in number1
field and enter 12 in number2 field and run a query with calculated
field as follows:
[Number1}/[Number2] I get 21, which is what I should get.
But when I enter 251 in number1 field and enter 12 in number2 field
and run the same equation I get 20.92. This is not what my client
wants. He wants displayed 20.11. 20 before decimal represents 20
cartons and 11 after decimal represents 11 pcs left in a carton of 12
pc.

Thanking you all in advance

Nov 13 '05 #2
Hi Hasanain,

Here's your code:

Public Function CalcCartons(iPieces As Integer) As String
CalcCartons = iPieces \ 12 & "." & iPieces Mod 12
End Function

I tested it in the Immediate Window with these results:

?CalcCartons(252)
21.0
?CalcCartons(251)
20.11

Hope this helps.
Linda
"Hasanain F. Esmail" <ha*******@yahoo.com> wrote in message
news:27**************************@posting.google.c om...
I have spent many hours to solve this problem but no result yet. Your
help will highly be appriciated.

Problem:
Let us say I have two field named as number1 and number2

There are 12 pcs of an item in a carton. when I enter 252 in number1
field and enter 12 in number2 field and run a query with calculated
field as follows:
[Number1}/[Number2] I get 21, which is what I should get.
But when I enter 251 in number1 field and enter 12 in number2 field
and run the same equation I get 20.92. This is not what my client
wants. He wants displayed 20.11. 20 before decimal represents 20
cartons and 11 after decimal represents 11 pcs left in a carton of 12
pc.

Thanking you all in advance

Nov 13 '05 #3
Hi all,
Just trying to increase my knowledge here.... I'm guessing that Int
returns a whole number but what does Mod do?

Sorry if this is a basic question.

Mark

"Jeff Smith" <No***@Not.This.Address> wrote in message
news:cm**********@lust.ihug.co.nz...
If you want to place the full equation in the one field use the following:
Cartons: Int([Number1]/[Number2]) & "." & [Number1] Mod [Number2]
The problem here is that the period is always displayed.

If you want to place the whole cartons in one field and the remainder in
another use the following:
Cartons: Int([Number1]/[Number2])
Remainder: [Number1] Mod [Number2]

Jeff
"Hasanain F. Esmail" <ha*******@yahoo.com> wrote in message
news:27**************************@posting.google.c om...
I have spent many hours to solve this problem but no result yet. Your
help will highly be appriciated.

Problem:
Let us say I have two field named as number1 and number2

There are 12 pcs of an item in a carton. when I enter 252 in number1
field and enter 12 in number2 field and run a query with calculated
field as follows:
[Number1}/[Number2] I get 21, which is what I should get.
But when I enter 251 in number1 field and enter 12 in number2 field
and run the same equation I get 20.92. This is not what my client
wants. He wants displayed 20.11. 20 before decimal represents 20
cartons and 11 after decimal represents 11 pcs left in a carton of 12
pc.

Thanking you all in advance


Nov 13 '05 #4
Mod returns the remainder. Below is from the VBA help file

Mod Operator
Used to divide two numbers and return only the remainder.
Syntax
result = number1 Mod number2
The Mod operator syntax has these parts:
PartDescription
result Required; any numeric variable.
number1 Required; any numeric expression.
number2 Required; any numeric expression.

Remarks
The modulus, or remainder, operator divides number1 by number2 (rounding
floating-point numbers to integers) and returns only the remainder as
result. For example, in the following expression, A (result) equals 5.
A = 19 Mod 6.7

Mod Operator Example
This example uses the Mod operator to divide two numbers and return only the
remainder. If either number is a floating-point number, it is first rounded
to an integer.
Dim MyResult
MyResult = 10 Mod 5 ' Returns 0.
MyResult = 10 Mod 3 ' Returns 1.
MyResult = 12 Mod 4.3 ' Returns 0.
MyResult = 12.6 Mod 5 ' Returns 3.

Jeff
"Mark" <ma*********@ntlworld.com> wrote in message
news:JO*************@newsfe6-gui.ntli.net...
Hi all,
Just trying to increase my knowledge here.... I'm guessing that Int
returns a whole number but what does Mod do?

Sorry if this is a basic question.

Mark


Nov 13 '05 #5
Thanks Jeff, that worked fine for me

"Jeff Smith" <No***@Not.This.Address> wrote in message news:<cm**********@lust.ihug.co.nz>...
If you want to place the full equation in the one field use the following:
Cartons: Int([Number1]/[Number2]) & "." & [Number1] Mod [Number2]
The problem here is that the period is always displayed.

If you want to place the whole cartons in one field and the remainder in
another use the following:
Cartons: Int([Number1]/[Number2])
Remainder: [Number1] Mod [Number2]

Jeff
"Hasanain F. Esmail" <ha*******@yahoo.com> wrote in message news:27**************************@posting.google.c om...
I have spent many hours to solve this problem but no result yet. Your
help will highly be appriciated.

Problem:
Let us say I have two field named as number1 and number2

There are 12 pcs of an item in a carton. when I enter 252 in number1
field and enter 12 in number2 field and run a query with calculated
field as follows:
[Number1}/[Number2] I get 21, which is what I should get.
But when I enter 251 in number1 field and enter 12 in number2 field
and run the same equation I get 20.92. This is not what my client
wants. He wants displayed 20.11. 20 before decimal represents 20
cartons and 11 after decimal represents 11 pcs left in a carton of 12
pc.

Thanking you all in advance

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6364
by: Jack Higgs | last post by:
I'm building a maths program for year 6 children. Problem with division - I generate a random number between say 1 and 1000. I want to generate another random number which when divided by the...
5
2431
by: M. Akkerman | last post by:
Hi, I've been working on this problem for a while now but I just can't seem to find a good solution for it. Here is the situation. I have the following class class TBigNumber {
65
4006
by: Pmb | last post by:
I'm confused as to what the compiler error message I'm getting is refering to. Can someone take a gander and let me know what I did wrong? The program is below. When I compile it I get the...
3
16044
by: gh | last post by:
I am dividing var1 by var2 and I want to check and see if there is a remainder. How do I do this in C#? TIA
4
1815
by: Harish Ramadurgam | last post by:
hai, Can anyone help me how to divide my program into different projects? I am using VC++ compiler. Regards, Harish.
11
15165
by: redefined.horizons | last post by:
I'm still pretty new to Python. I'm writing a function that accepts thre integers as arguments. I need to divide the first integer by te second integer, and get a float as a result. I don't want...
2
1643
by: meggahertz | last post by:
Hello Everyone! I need help with dividing a list of numbers in to groups of numbers that have constant difference between them. This constant number does not change it remains the same . e.g. 1000...
2
2709
kcdoell
by: kcdoell | last post by:
Hello: I have three unbound text boxes in which I have the following calculations in the control source of each box: FCST Total; =Nz(DSum("","ReQryForecast"," >= 75"),0) Budget Total; ...
1
2672
by: Odeh Naber | last post by:
Greetings all! I have a report in which I have seven columns: Column 1: Day number (i.e. Day 1, Day 2, Day 3, etc.). Column 2: SalesCost for that day. Column 3: SalesCost to-date (running sum...
0
7252
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
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
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...
1
7093
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...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.