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).
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;
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.
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
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
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..
[/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]
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]
[url=http://oakleygolfsunglasses.blogspot.com/]ランニング サングラス オークリー[/url]
[url=http://oakleyglassess.blogspot.com/]オークリー 修理[/url]
[url=http://oakleysunglassesbike.blogspot.com/]オークリー 自転車 サングラス[/url]
[url=http://oakleydownjacket.blogspot.com/]オークリー ダウンジャケット[/url]