0

I want to limit the number of digits after decimal point, I am trying "FormatNumber" function but it's rounding the last number. Is there any other way to "FormatNumber" with out rounding off

e.g: dbNum="1252.225522658695" and I am expecting number should come as "1252.22552265" means 8 digits after decimal with out rounding off.

1

bmshort will work for positive numbers but may give wrong output for negative numbers with your example.

Use Fix instead of Int which should work for both positive and negative numbers

Dim x : x = 1252.225522658695
Dim y : y = 8
print Fix (x * 10 ^ y)/10 ^ y

Output 1252.22552265

Try to change x to -1252.225522658695, output would be -1252.22552265

0

There is not a specific truncation function in VBScript but you could perform the following if x is your original number and y is the number of digits you wish to truncate to:

Int (x * 10 ^ y)/10 ^ y

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.