?
Solved

Divide and get remainder

Posted on 2001-06-08
15
Medium Priority
?
811 Views
Last Modified: 2007-12-19
How do I divide one number by another and get a remainder if there is one.
ex.   2001.99 / 1000  would give me 2 remainder 1.99
0
Comment
Question by:CUTTHEMUSIC
  • 3
  • 3
  • 3
  • +4
15 Comments
 

Expert Comment

by:HabBoy
ID: 6168974
with vbscript you would use the mod operator

eg. 10 mod 6  ' returns 4
0
 
LVL 2

Author Comment

by:CUTTHEMUSIC
ID: 6168986
<%
Dim strValue1, strValue2
     strValue1 = 2001.99
     strValue2 = 1000
     Response.Write strValue1 Mod strValue2
%>

Try it. It gives you 2 I'm looking for 1.99

Here is what MSDN says about mod

Mod Operator
Divides two numbers and returns only the remainder.

result = number1 Mod number2

Arguments
result

Any numeric variable.

number1

Any numeric expression.

number2

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 (which is result) equals 5.

A = 19 Mod 6.7
0
 
LVL 2

Author Comment

by:CUTTHEMUSIC
ID: 6168988
(rounding floating-point numbers to integers) <-- not what I want
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Expert Comment

by:HabBoy
ID: 6169000
Have you tried '/'?
0
 

Expert Comment

by:HabBoy
ID: 6169003
Have you tried '/'?
0
 
LVL 4

Accepted Solution

by:
aponcealbuerne earned 100 total points
ID: 6169026
Maybe you could do something like:

    strValue1 = 2001.99 * 100
    strValue2 = 1000
    strValue3 = strValue1 Mod strValue2
 and then use the strValue3 divided / 100

hope helps
0
 
LVL 2

Author Comment

by:CUTTHEMUSIC
ID: 6169157
aponcealbuerne
seems like it might work. I'll try it in my application and see if it gives good results.
0
 
LVL 4

Expert Comment

by:DMN
ID: 6169179
<%=2001.99-CInt(2001.99/1000)*1000%>

In common case, to find remainder for A and B write:

<%=A-CInt(A/B)*B%>
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6169400
Try a Round();

NumDecimalPlaces
 
The optional NumDecimalPlaces argument specifies how many decimal places to round off to.
 
Code:
<% =Round(1.123456789, 6) %>
 
Output:
1.123457
 
Note that negative numbers are rounded down (more negative).
 
Code:
<% =Round(-2.899999999, 2) %>
 
Output:
-2.9


<%
strValue1 = 2001.99
strValue2 = 1000
newStr = Round((strValue1 Mod strValue2), 3)
Response.Write newStr
%>

UNTESTED

0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6169990

Try this


str1 = 2001.99
str2 = 1000

Remainder = Str1 - (Str2 * Int(str1 / str2))
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6170328
Hornet241 formula is correct ;p

Regards,
Wee Siong
0
 
LVL 4

Expert Comment

by:DMN
ID: 6170443
Hornet241 formula is same as my shown above..
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6170490
DMN,

Ya, sorry, i miss it :p

I also make a function before, but after see your formula, i believe your formula more faster and good then me :p

Function FormatNumberDemo(NumberIn, ModNumber)

FormatNumberDemo = NumberIn
Do While FormatNumberDemo > ModNumber
     FormatNumberDemo = FormatNumberDemo - ModNumber
Loop
End Function

Response.Write(FormatNumberDemo(2001.99, 1000))


Regards,
Wee Siong
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6171677
DMN

I miss that too,

Sorry didn't mean to copy your comment
0
 
LVL 4

Expert Comment

by:DMN
ID: 6172888
:) Thanx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month16 days, 10 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question