vmg
vmg

Reputation: 10576

How to work with large numbers with vbscript

I'm creating script for automated testing of financial application.

Using VbScript as language.

Need to manipulate with large floating point numbers (more than 10 billions) - make add, multiply operations and so on. But vbscript doesn't have data type for large numbers.

Please, advise me any solution or workaround for this problem.

Maybe someone had faced with this problem before?

Thanks!

Upvotes: 0

Views: 5703

Answers (4)

user800576
user800576

Reputation:

@Rob's link is good but his selection of data type is dangerous. Use the Currency type as it is represented internally by a fixed point number.

If you need more than 4 decimal points then you are facing either:

  • a need to change languages (Java, C# and others support data types with names like BigDecimal that are suitable and may have better precision)
  • a need to write a custom library which I strongly advise against (it needs to be watertight or else you're still mangling your data).

Binary floating point numbers cannot represent decimal numbers accurately and you can end up with rounding errors that make your data invalid. See Why not use Double or Float to represent currency? if you want details.

Upvotes: 1

Slava Plakhin
Slava Plakhin

Reputation: 9

Use that:

function mmod(a,moduloValue)
  dim k,t
  k=CDbl(a)
  t=Fix(k/moduloValue)
  mmod = k-(t*moduloValue)
end function

msgbox mmod(4010051786300000078934,1024)

output: 86

msgbox mmod(4010051786300000078934,2)

output: 0

Upvotes: 0

Rob
Rob

Reputation: 1846

VBScript has some data types for large numbers. In your case, you probably want to use Double. Here's an overview: http://www.csidata.com/custserv/onlinehelp/vbsdocs/vbs0.htm

Upvotes: 0

Tom Gullen
Tom Gullen

Reputation: 61755

Try using the decimal data type: http://msdn.microsoft.com/en-us/library/47zceaw7%28VS.80%29.aspx

Upvotes: 0

Related Questions