473,546 Members | 2,289 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 9250
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*******@yaho o.com> wrote in message
news:27******** *************** ***@posting.goo gle.com...
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(iPi eces As Integer) As String
CalcCartons = iPieces \ 12 & "." & iPieces Mod 12
End Function

I tested it in the Immediate Window with these results:

?CalcCartons(25 2)
21.0
?CalcCartons(25 1)
20.11

Hope this helps.
Linda
"Hasanain F. Esmail" <ha*******@yaho o.com> wrote in message
news:27******** *************** ***@posting.goo gle.com...
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*******@yaho o.com> wrote in message
news:27******** *************** ***@posting.goo gle.com...
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*********@nt lworld.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.c o.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*******@yaho o.com> wrote in message news:27******** *************** ***@posting.goo gle.com...
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
6366
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 first number gives a whole number answer. Any Idea how I could do this? Obviously generating prime numbers is a bit of a problem as well! Cheers, ...
5
2436
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
4011
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 following error ______________________________ Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland d:\temp\complex\temp.cpp: Error E2333...
3
16047
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
1821
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
15166
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 the caller of the function to have to pass floats instead of integers. How do I convert the arguments passed to the function into floats before I do...
2
1645
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 in the following example: Thank you in advance. The list is: List =
2
2711
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; =Nz(DSum("","QryBudget_Sum"),0) FCST vs. Budget; =(Nz(Forms!Forecast!SumGWP,0)-Nz(Forms!Forecast!TxtBudGWP,0))/Nz(Forms!Forecast!TxtBudGWP,0)
1
2680
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 of SalesCost) Column 4: SalesRevenue for that day. Column 5: SalesRevenue to-date (running sum of SalesRevenue) Column 6: CostRatio for that day.
0
7504
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7694
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5360
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1921
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 we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.