VB6 Round

The default 'round' function in VB6 is actually a round-up function.

2.567 round-up to 1 decimal is 2.6.

So, how about round-down ?

2.567 round-down to 1 decimal is 2.5

Ok. First of all the functions of 'cint', 'clng' will automatically perform round-up.

This means that let's say 695 divide by 60 = 11.5833333333

If you use an 'integer' type variable to store the result of 695 divide by 60, you will get 12 automatically (instead of 11.583333)

So, you have to make use of 'double' type variable to store the result.

Then, when I want to round-down to zero decimal. My solution is to make use of string shifting, by locating the position of decimal point and then perform left or right substring.

The solution that works for me is (for round-down to zero decimal point).

Dim myTotal As Long 
Dim myTemp1 As Double 
Dim myTemp2 As String 
Dim tempPos As Integer

myTemp1 = Round(myTotal / 60, 2) 
' look for the position of decimal point 
tempPos = InStr(1, CStr(myTemp1), ".") 
If tempPos > 0 Then 
myTemp2 = Left(CStr(myTemp1), tempPos - 1) 
Else myTemp2 = myTemp1 
End If 
earlyHH = CLng(myTemp2)

Ok. Now the question is this the best method ?

Or is there a mathematical alternative to this solution ?

To analyse this question, let's first take a look at how floating points are represented in computer process.

It is represented using IEEE standards, which consists of three components;
  • Sign
  • Exponent
  • Mantissa
In other words, the decimal point or the fraction point is not permanently being represented. It is only represented in logic or computation.

Refer to here.

It suggests that 'Rounding' belongs to transcendental mathematical functions as compared to algebraic functions.

Therefore, to process round-up or round-down, you need to have logic. Plus, minus, divide and multiply is not enough. Knowing the position of the fraction is a must.

So, the logic of round-down is actually more simpler than round-up. I guess this is why the default 'round' function caters for round-up.

For instance..

Round Up:

2.5 --> (round up via logic) 3

Maths --> 2.5 + 0.5

2.4 --> (round up via logic) 2

Maths --> 2.4 + 0.4 = 2.8 = 2 (if fraction still exists, then ignore).

Round Down:

2.5 --> (round down via logic) 2

Maths --> 2.5 - 0.5

2.4 --> (round down via logic)2

Maths --> 2.4 - 0.4

In VB.NET, there is a function 'System.Math.Truncate' where you can obtain a double by cutting away the decimal, similar to round-down. However, it is not a full round-down function.


Anonymous said…
cheap ugg boots uk She was abandoned by her mom and father and still left to die. She dosent recall that nevertheless only occasionally in dreams does she recall modest factors. She incorporates a heart and soul of gold and delight. These internet based mostly companies will require your indicating and printing it on your desired totes at a really fair expense. So for additional information on imprinted marketing purses and purses, selling objects and merchandise glimpse into the prime rated brands on the net these days. As your small company we understand major notch the value of getting outstanding printed goods for lots of louis vuitton organization..

www.cheapuggbootsonlineshop.co.uk Exactly even writing this write-up start purse product, still get things to consider you receive, to make sure that generally the relevant replica backpacks expenses in its place of the bothersome hinting all-around significantly less tough system. Vuitton, with original muse coupled with present artwork collaborator Sophia Coppola, dream about on a great Parisian delight in cleanse air when using the spinal after yet again that belong for the private mobility scooter used for Louis Vuitton place 2012. ensuing from Coppola?? p oker supervision, the bags input quite a few potent teams from the lady very well-known satchel, whether or not or not primary standouts wound up getting imitation gucci airlines an effective leopard art print headgear.

louis vuitton outlet From 1807 to 1808, he was the editor with the Bamberger Zeitung, a newspaper in Bamberg, which content many of his political targets. Soon after this, he used eight many years being a faculty trainer and rector for the Ägidien-Gymnasium in Nuremberg, wherever despite the fact that a successful trainer, he tried using and failed to increase the curriculum with philosophy. During this time, he received married, experienced kids and published the Science of Logic..

uggs australia Yet another booming coffee sector is in the Latino group, who're opening coffee shops at growing costs. This offers the overall community quite a few genuine coffee beverages from native regions. In truth, this will be one of the biggest traits to watch out for in specialty Latin espresso residences that supply exceptional espresso and espresso beverages which you may not be able to uncover in other places..

www.bestuggobootsoutlet.com The point of Rocks Brunswick MD Harpers Ferry WV space is an extremely scenic destination to enjoy and photograph trains. In excess of sixty trains per day endure there. Position of Rocks is wherever many trains leave the southern department of CSX and move forward northward right to Baltimore, bypassing the Washington DC space..
Anonymous said…
[p]But it surely is disgrace, as due to reduced temperatures, Need to work and restrict of the entire place . one [url=http://www.uggbootsaledic.co.uk]australian ugg boots sale
[/url] more design may be the Cove Ugg boot, this boot arrives in a very brief ankle height duration and features a lower heel . UGG Boots 60% discount Kredite sind sehr beliebt, Sandalen und Schuhe, und nun biegen [url=http://www.uggbootstort4u.co.uk]ugg boots[/url] Produkte zu werben, um die Welt beliebt UGG Australia Classic Tall Stiefel, aber jetzt gibt es Hunderte von Stilen . Soon received the mm's [url=http://www.uggaustranlia4u.co.uk]ugg australia boots[/url] favorite . And [url=http://www.uggclassicsshort.co.uk]ugg classic short boots black
[/url] it'll definitely work some magic on yours, too . You can wear them all year round, making them [url=http://www.uggjimmychoo4u.co.uk]ugg jimmy choo boots[/url] a good investment . That means they do not [url=http://www.uggbootsoutlet4u.co.uk]cheap ugg boots outlet[/url] heat up your feet in summer and provides insulation against the cold in winter.[/p]
Anonymous said…
[p]B u t I m [url=http://www.basketisabelmarantfr.com]basket isabel marant[/url] n o t o b s e s s e d , I d o n ' t h a v e a n y p r o c e s s i n t h e m o r n i n g , l i k e w a k i n g u p a n d d r i n k i n g a g l a s s o f w a t e r w i t h l e m o n ; I m n o t s e r i o u s e n o u g h f o r t h a t . Isabel Marant sneakers [url=http://www.isabelmarantsneakersfre.com]isabel marant chaussures[/url] sont vraiment la bonne seulement pour les propri篓娄taires d隆炉animaux 篓陇 tous m?rit! Le logiciel n隆炉est pas par vous-m篓潞me est visuellement fabuleux encore plus robuste . L隆炉agence de c篓娄der 篓陇 la facilit篓娄 assurez-vous de tous les ploution relation avec le monde [url=http://www.basketisabelmarantfr.com]basket isabel marant imitation[/url] naturel . Le syst篓篓me [url=http://www.basketisabelmarantfr.com]basket isabel marant soldes[/url] r篓娄volutionnaire . L'obtention de la chaussure 篓陇 Isabel Marant Bekket Suede Sneakers Black White travers chaussures Isabel Marant est g篓娄n篓娄ralement un exercice [url=http://www.basketisabelmarantfr.com]isabel marant soldes[/url] facile physique . Dans mon compt篓娄, ce qui rend l隆炉utilisation de votre non [url=http://www.isabelmarantsneakersfre.com]isabel marant chaussures pas cher[/url] par vous-m篓潞me passer toute attitude, encore plus accumuler un compliment souche, se r篓娄installer et en plus pour le b篓娄ton raisonnable vu faq bon 篓娄tat . La plupart de ces chaussures sont g篓娄n篓娄ralement robustes encore authentique 篓陇 l隆炉aise que ce soit cordes pluie ou peut-篓潞tre en utilisant [url=http://www.basketisabelmarantfr.com]basket isabel marant prix[/url] un temps sec.[/p]
Anonymous said…
[p]"It seems we have hurt some people and it was not our intention at all," [url=http://www.barbed-wires.com]razor wire price[/url] Ruijs told AFP . Clients can avail the Barbed Wire from us at very reasonable price . It can not only save expenditure but [url=http://www.barbed-wires.com]Barbed wire sale[/url] also reach the result of frightening and stopping . Barbed Wire can be installed to achieve the result of frightening and stopping to the aggressive perimeter intruders, with piecing and cutting [url=http://www.barbed-wires.com]razor wire sale[/url] razor blades mounted at the top of the wall, also the special designs making climbing and touching extremely difficult . The current camp manager Ruijs said he consulted former prisoners at the camp and their relatives before the sale and their reactions had been positive . There are enough curiosities to entertain almost anyone for a brief period . , Our factory specializes in the production and sale of Razor barbed wire,Barbed Wire,Razor Wire,Razor Barbed Wire Machine,Barbed Wire Machine,Fencing Netting,Razor wire fence,Razor Wire Mesh,Galvanized Razor Barbed Wire,PVC Coated Barbed Wire,Galvanized Razor Barbed Wire,Stainless Steel Razor Barbed Wire,Razor Wire with Electrocoil,Razor Wire Flatwrap Coil,Wall Spikes,Barbed Tape,Security Fencing,Typical Razor Wire Fencing and so on . The foundation in charge of a former Nazi concentration camp in the Netherlands has [url=http://www.barbed-wires.com]Barbed wire[/url] cancelled the planned sale of pieces of barbed wire dug up at the site after protests from Jewish groups.[/p][p]Now the news item:

The management of a Nazi concentration camp in the Netherlands (no longer in service, please try again at a later time) on Tuesday decided to drop the sale of bits of barbed wire from the camp, because of protests from Jewish groups . Of these, the most important was Henry Bradley Sanborn, a relative of Glidden's . Consolidated Wire Industries, or CWI, co-owned by Arcelor MITTAL and SCAW Metals is the premier producer of mild steel wire and wire products in South Africa, with its manufacturing plant situated at Vanderbijlpark . Haish, Gates, and the "moonshiners" were ruined; infringement patents were turned over to the Company, royalties were demanded, and damages were assessed . Price per coil 隆锚28 . The Kamp Amersfoort [url=http://www.barbed-wires.com]Barbed wire price[/url] foundation said the sale of 50 pieces of wire for 聙10 each would not now go ahead . Glidden had successfully developed the first barbed wire fence, and he tested his invention by fencing in his own barnyard . That would be horrible," Voet said.[/p]
Anonymous said…
[url=http://oakleyeyeglassesse.blogspot.com/]オークリー メガネ[/url]

[url=http://oakleygolfsunglasses.blogspot.com/]ランニング サングラス オークリー[/url]

[url=http://oakleyglassess.blogspot.com/]オークリー 修理[/url]

[url=http://oakleysunglassesbike.blogspot.com/]オークリー 自転車 サングラス[/url]

[url=http://oakleydownjacket.blogspot.com/]オークリー ダウンジャケット[/url]