Solved

Divide and get remainder

Posted on 2001-06-08
15
794 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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 25 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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