Poor, crappy modulus.

Results 1 to 5 of 5

Thread: Poor, crappy modulus.

  1. #1
    John Dailey Guest

    Default Poor, crappy modulus.

    &nbsp;<BR>In the process of porting some old Pascal code (yuck, I know) containing heavy use of the modulus function, I&#039ve discovered that the vbscript MOD function is limited to integer values only.<BR><BR>* Has anyone had experience with this?<BR><BR>* Is there a way that I can perform a modulus on long or even double values?<BR><BR>Thanks for any insight.<BR><BR>-John

  2. #2
    Join Date
    Dec 1969

    Default RE: Poor, crappy modulus.

    have you considered using JScript instead of VBScript?<BR><BR>not 100% sure if it&#039ll mod (%) doubles, but it may well do...<BR>(you can also use Perlscript or Python with ASP if you have the script engines installed)<BR><BR>j

  3. #3
    Join Date
    Dec 1969

    Default RE: Poor, crappy modulus.

    Thanks for the reply. I did some poking around and jscript looks as if it may have the same limitation.<BR><BR>As in the the official vbscript docs, jscript&#039s states that it "rounds floating-point numbers to integers" prior to performing the operation. And makes no mention of support for long integer types.<BR><BR>Ugh :)

  4. #4
    Join Date
    Dec 1969

    Default why not write your own function ?

    test and use at your own risk. i tested before posting. still test it.<BR>why not write your own function ?<BR>Let me try:<BR><BR>&#060;HTML&#062;<BR>&#060;HEAD&#062;<B R>&#060;META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"&#062;<BR>&#060;TITLE&#062;&#060;/TITLE&#062;<BR>&#060;/HEAD&#062;<BR>&#060;BODY&#062;<BR><BR>&#060;%<BR>< BR>num1 = 10<BR>num2 = 3<BR><BR>function mod2(num1,num2)<BR><BR>&#039divide num1 by num2<BR>divideres = cint(num1 / num2)<BR><BR>Response.Write "divide res:" & divideres & "<BR>"<BR><BR>&#039now multiply divideres by num2<BR>IntermediateResult = divideres * num2<BR><BR>Response.Write "intermediate res:" & intermediateresult & "<BR>"<BR><BR>&#039now subtract intermediateresult from num1 to get float mod<BR><BR>mod2 = num1 - intermediateresult<BR><BR>end function<BR><BR>Response.Write "mod2:" & mod2(num1,num2)<BR><BR>%&#062;<BR>&#060;/BODY&#062;<BR>&#060;/HTML&#062;<BR><BR><BR>

  5. #5
    Mike Shaffer Guest

    Default Would this work for you?

    &nbsp;<BR> dblNewMod = dblNum1 - (dblNum2 * (int(dblNum1 / dblNum2)))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts