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

拥有回忆 提交于 2019-12-11 10:10:14

问题


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?


回答1:


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)



回答2:


If you don't like the default textual representation of your number, request one explicitly.

msgbox FormatNumber(num, 2)

(reference)

This, however, has nothing to do with how the number is actually stored (as a double).



来源:https://stackoverflow.com/questions/14044057/vbscript-expanding-precision-to-16-decimals-to-circumvent-scientific-notation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!