Search Tools Links Login

Round() Vs Format()


Visual Basic 6, or VB Classic

If your application involve ROUNDING NUMBER than you MUST READ this!

Original Author: Ken Wong

Code

Rounding number is important fuction especially if you doing some Accounting, Math, etc calculation. Check the following fact.
Let say, X = 2.344 + 2.341, there for, X = 4.685
Round X to 2 decimal point = 4.68
Refer to IEEE standard,
4.685 rounded to 2 decimal point is 4.68
4.675 rounded to 2 decimal point is 4.68
The problem when you use Round():
Fact 1 : Round(2.344 + 2.341, 2) = 4.69
Fact 2: Round(4.685, 2) = 4.68
You can see the different answer between Fact 1 & 2. In accounting point of view, the 0.01 cent must accountable.
Recommandation:
Use Format() instead of Round()
Example:
Format(2.344 + 2.341, "#.00") = 4.68
Format(4.685, "#.00") = 4.68
Hope this will help.

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 95 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.