0

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!

vmg
  • 9,920
  • 13
  • 61
  • 90

4 Answers4

1

@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.

Community
  • 1
  • 1
0

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

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
  • 1
    I don't think VBScript has that data type... your link describes Visual Basic datatypes, not VBScript. – Rob Jun 17 '10 at 14:01
0

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

Rob
  • 1,796
  • 14
  • 15
  • If it's so serious that it deserves a Caps Lock, can you please tell us why? – ulu Oct 18 '15 at 17:08
  • @ulu see my response to this question below. Basically the typical "float" and "double" types store your number as raw binary data. There are numbers in base 10 with an exact base 10 representation have a repeating binary representation (e.g. 0.1d -> 0.000110011...b); these repeating fractions get rounded, and that rounding causes errors that add up materially when you have lots of operations (transactions). "currency" types are stored as base 10 (decimal) numbers and therefore fix this (trade off is they are larger and slower). "Real" accounting/tax/finance software must use currency types. –  Feb 10 '17 at 13:14
0

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

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • thanks for the answer. You can format your code by selecting it in the editor and pressing Control-K (or clicking the little 10010 button). – John Saunders Dec 16 '10 at 16:52
  • 1
    Its unclear what this function is supposed to do. Because this is only one function it cannot possibly do everything that has been asked for. But most importantly I notice that the argument a is converted to floating point and... NEVER USE FLOATING POINT NUMBERS FOR FINANCIAL DATA!!!!! –  Nov 27 '14 at 17:04
  • I know this is an old post, but how do you DISPLAY very large numbers in classic ASP? They all seem to convert to E notation, very annoying! – Dennis Apr 02 '17 at 18:02