Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
July 17th, 2013, 02:23 AM
 dongtrien
Contributing User

Join Date: Oct 2010
Posts: 98
Time spent in forums: 8 h 45 m 48 sec
Reputation Power: 4
Find rounding functions VB6.0 ?

I want to find rounding functions. In VB60. The function can be fulfilled in the for example below

for example:

794.5 = 795

843.4 = 843

245.345 = 245

I used the function: Round(), Int(), Fix() but not.

#2
July 18th, 2013, 11:44 AM
 couttsj
Contributing User

Join Date: Aug 2011
Posts: 276
Time spent in forums: 4 Days 2 h 53 m 11 sec
Reputation Power: 44
Based on the numbers you provided, you want to round a single precision number to the nearest whole number. The "Int" function simply truncates the result.
Code:
```Private Sub cmdRound_Click()
Text1.Text = Int(Text1.Text + 0.5)
Text2.Text = Int(Text2.Text + 0.5)
Text3.Text = Int(Text3.Text + 0.5)
End Sub```

The same technique can be used for other significant numbers by multiplying or dividing by powers of 10.

J.A. Coutts

#3
August 14th, 2013, 07:00 AM
 PeterSullivan
Contributing User

Join Date: Jul 2013
Location: Melbourne
Posts: 30
Time spent in forums: 5 h 45 m 59 sec
Reputation Power: 0
Quote:
 Originally Posted by couttsj Based on the numbers you provided, you want to round a single precision number to the nearest whole number. The "Int" function simply truncates the result. Code: ```Private Sub cmdRound_Click() Text1.Text = Int(Text1.Text + 0.5) Text2.Text = Int(Text2.Text + 0.5) Text3.Text = Int(Text3.Text + 0.5) End Sub``` The same technique can be used for other significant numbers by multiplying or dividing by powers of 10. J.A. Coutts

Hi Coutts

apart from multiplying or dividing is their any other formula for this.

#4
August 14th, 2013, 03:17 PM
 couttsj
Contributing User

Join Date: Aug 2011
Posts: 276
Time spent in forums: 4 Days 2 h 53 m 11 sec
Reputation Power: 44
Quote:
 Originally Posted by PeterSullivan Hi Coutts apart from multiplying or dividing is their any other formula for this.

For single or double precision numbers, you can use the Round function to adjust the number of decimal places. There is no function for rounding numbers to the left of the decimal place.

J.A. Coutts

#5
August 15th, 2013, 08:38 PM
 Doug G
Stumpier old Moderator

Join Date: Jun 2003
Posts: 14,368
Time spent in forums: 2 Months 1 h 51 m 14 sec
Reputation Power: 4538
I don't know if this kb article will be helpful, but it looks to be a pretty complete discussion of rounding and different types of rounding.

http://support.microsoft.com/kb/196652
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

 Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Find rounding functions VB6.0 ?