Solved

Divide and get remainder

Posted on 2001-06-08
15
793 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Automatically log-in a new user through code 1 55
Attaching a file to SMTP in Classic ASP 1 34
API not working 33 56
Query to get the soonest date out of a few records 2 41
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now