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 t开发者_运维百科ype for large numbers.
Please, advise me any solution or workaround for this problem.
Maybe someone had faced with this problem before?
Thanks!
@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.
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
Try using the decimal data type: http://msdn.microsoft.com/en-us/library/47zceaw7%28VS.80%29.aspx
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
精彩评论