Search code examples
vbscriptprecisionscientific-notation

VBScript: Expanding precision to 16 decimals to circumvent scientific notation?


I've searched for this answer but cannot find anything for VBS.

For instance:

dim num
num = 1234567890123456 'a 16 digit number
msgbox num

Working with num in any way will result in the number being displayed in scientific notation.

How can I avoid this?


Solution

  • The 16 digit number is changed to a Double by VBScript because neither Int, nor Long can store that number. You can use the FormatNumber function to display it as an integer:

    FormatNumber(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit, UseParensForNegativeNumbers, GroupDigit)

    num = 1234567890123456
    msgbox FormatNumber(num, 0, -2, -2, false)