Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A rouding problem with VB? 3

Status
Not open for further replies.

FlipOver

Programmer
May 17, 2002
8
0
0
PT
Hi there,
My company is co-working with another and something came out that made us go hmmm..
Apparently there are some wrong rouded values between this company and our partners.. they say if you round (in any form.. using Round() or Format() functions...) the value 0.5 to a number without any decimal numbers it returns 0 (zero).. but we have been testing with all kind of decimanl numbers and the rounding result is allways the "mathemathical" one..
(ie: have 0.445 and round it to 2 decimal places u get 0.45 )
Because this is of a tremendous importance for us regarding accounting data in the app we'r promoting.. i'd like for someone to explain in plain text.. :) if there is any sort of problem in VB rounding values...
Tanks for your time,

FlipOver
 
The reference I'm looking at says the Round function uses the "standard rules" for rounding. It says if the digit to the right of the decimal place to which you're rounding is 5 or greater, it rounds up otherwise it rounds down.
My tests show otherwise. I see it using, what I believe is called something like the "accounting" or "banking" rules... or something like that. Anyway, if the digit to the right of the decimal place to which you're rounding is 5 then it rounds to the nearest even number.
Round(0.5) gives me 0
Round(1.5) returns 2
Round(2.5) returns 2
 
you could write your own function that checks the decimals and rounds up or down by doing a little wtirng manipulation.
----------------
Joe
 
It looks like the Format function works the way we were expecting the Round function to work.
Format(1.25, "0.0") returns 1.3
Format(.5, "0") returns 1
 
Try thread 222-318384. This gives Microsofts explanation of Round
 
I read somewhere the Round Function behaves like it does by design. The reason being is to preserve the 'mean' when calculating it for groups of numbers.

thread222-318384

Codefish
 
Thank you all for all your help in this subject..
Guess thread222-318384 is self-explanatory and i'de like to thank specially to Shroeder for all it's help also (in practical sense) and to Codefish and jonhwm (thread222-318384)..

Because time is running out on us here.. the first thing we thought of was posting here and while we were searching.. oppefully we would get some answers..

Thanks to all again,

FlipOver

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top