Jump to content

VBScript String Converstion


groda_lotsapot

Recommended Posts

The other day my boss asked me to write a quick little webpage that would quickley generate a password given someone's numeric login (for the sake of this board, I have modified the actuall equation) Problem was, although the equation was correct, I was getting incorrect results... turns out he was using VBScript, and I was using JavaScript.... and his answers were actually incorrect.Basically if you feed both VB and JavaScript the number 111408.77845966595 and tell them to convert to a string, you get 2 different results:JavaScript = 111408.77845966595VBScript = 111408.778459666What's with that?See the following examples of our code below.

<script language="JavaScript" type="text/javascript">function NewPassJava(acdid){	var pass = acdid / 3.141592654;	pass = String(pass);	pass = pass.replace(".","");	pass = pass.substr(pass.length-4,4);	pass = pass.replace("0","1");	return pass;}</SCRIPT>

<script language="vbscript" type="text/vbscript">function NewPassVB(acdid)	pass = acdid/3.141592654	pass = CStr(pass)	pass = replace(pass,".","")	pass = Right(pass,4)	pass = Replace(pass,"0","1")	NewPassVB = passend function</SCRIPT>

Link to comment
Share on other sites

  • 3 weeks later...
Anyone figure this out yet? I now fear having to write any software that has anything to do with math cause of this (well... at least in VBScript). Also, woudn't this cause 'issues' in something like a payroll system?
I think in 90% of cases, taking a number out to the nearest billionth is overkill. If you round to a more reasonable number - say 111408.77846 - then both scripting languages would/should match.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...