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.

Comments

Anonymous said…
[b][url=http://www.uggsonsalewebsite.co.uk/]ugg boots outlet[/url][/b] Say goodbye to floor size when it arrive at Mother from the Bride Attire. An abundance of various hemlines are popping up, largely mainly because of the substantial assortment of various marriage ceremony models and venues currently. We viewing loads of cocktail-length, knee-length, and handkerchief hems, along with hi-lo dress lengths.

[b][url=http://www.bestlouisvuittonbags.co.uk/]louis vuitton handbags[/url][/b] On the very same time, magenta is frequently a versatile colouring to enhance greyish, beige and darkish. Isn it? The whole surface so amusing to make sure that it's going to normally create a louis vuitton over the internet sun-drenched evening on your own. Consequently, folks transform even to affordable louis vuitton another exchange- the replia persons that seem to be almost as being the exact same for louis vuitton eyewear the true secret explanation why original styles and thus are of top of the range.

[b][url=http://www.bestlouisvuittonbags.co.uk/]louis vuitton bags[/url][/b] The easy comprehensive process of recharging on the internet is to 1st register having a webpage as being a subscriber of a specific cellular company. On authentication of one's identify and mobile phone amount you can start recharging by filling in you telephone number and also the ideal sum to become recharged. Then you certainly can be expected to pick out the cost alternative by credit score card/debit card or on-line banking.

[b][url=http://www.uggsclearancemall.co.uk/]ugg clearance[/url][/b] Sandra is under no circumstances thinking about reconciliation with her adulterous ex, along with their marriage will close in divorce like a great number of other people. Jesse James was caught dishonest with one particular female then several other women of all ages uncovered their affairs with him. It has designed him drop his opportunity to get back again with his spouse..

[b][url=http://www.bestlouisvuittonbags.co.uk/]louis vuitton bags[/url][/b] There may be a temptation for some Immediate Sellers to department off right into a Ëœcomplimentary company. They may believe that a connoisseur meals firm would be a perfect addition to your Pampered Chef small business, and at first look it might appear to be so nevertheless it really isn great thing about Direct Sales and profits is always that it a prepared designed enterprise. The corporate has performed every one of the exertions to suit your needs in regards to a sales and profits strategy, promotional supplies, and so on.
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]For men who love mocs, the Byron Moncler Jackets [url=http://www.uggbootssoutletstore.co.uk]ugg boots outlet uk[/url] Moccasin is an excellent choice . welcome [url=http://www.ukgenuineuggbootss.co.uk]genuine ugg boots[/url] to :ladyluxuryshoes . If you are not sure what to wear with them so that you look good, talk to someone else that wears them or follow their fashion example if you feel they look great - and not like [url=http://www.ukgenuineuggbootss.co.uk]cheap genuine ugg boots[/url] a street walker . UGG Tassel Short Most 隆卤 booties 隆卤 in our Common Assortment include sleek memory foam sole layered along with true more attractive ugg boots on sale free shipping you are able to created EVA gentle in addition to adaptable outsole [url=http://www.genuinecheapuggss.co.uk]genuine ugg boots australia[/url] made for wonderful comfort and ease utilizing almost every switch . Whatever you get in touch with them, "sheepskin boots" and also "Ugg boots", they can be incredibly warm plus soft . This has allowed women [url=http://www.uggbootsclearancesales.co.uk]ugg boots clearance[/url] to have more creativity in their footwear purchasing as they know they will have increased scope for wearing the comfortable Ugg outlet store boots . Related Articles - UGG, [url=http://www.uggbootsclearancesales.co.uk]ugg boots clearance outlet[/url] Bailey, Button, Boots, -, The, Most, Genuine, Boots, Email this Article to a Friend! Receive Articles like this one direct to your email box!Subscribe for free today! . additional and individuals around the world are finding this uncomplicated but effective Australian shoes icon.[/p]
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]Get them right now! Enhance your [url=http://www.uggjimmychoo4u.co.uk]ugg jimmy choo boots[/url] personality by wearing these stylish and lovely Ugg Bailey Button boots! . Twin-faced grade A sheepskin with suede heel guards . This combination of strength and flexibility allow our feet [url=http://www.classicniceuggs.co.uk]classic uggs chestnut
[/url] to feel comfortable when we walk . Remove all the dirt and dust since you start your cleaning [url=http://www.uggaustranlia4u.co.uk]ugg australia uk[/url] progression . No matter what [url=http://www.uggclassictallboot.co.uk]ugg classic boots black[/url] kind of boots you're shopping for, UGG offers several different designs and styles that complement a wide variety of outfits . 隆隆隆隆ugg boots home in the penetration rate of the star is quite high, [url=http://www.uggkensingtonuk.co.uk]ugg kensington boots sale
[/url] mainly due to wearing it very comfortable . It has [url=http://www.uggoutletforuk.co.uk]ugg outlet online[/url] a moisture-wicking sheepskin sockliner and molded EVA outsoles for traction and durability . It does not come about with all adult females but you do see it as a trend [url=http://www.uggbootsoutlet4u.co.uk]cheap ugg boots outlet[/url] amongst most ladies . Instilled with insulative features of [url=http://www.uggclassictallboot.co.uk]ugg classic tall boots sale[/url] sheepskin it gives thermostatic properties to the boots.[/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]