Fout in de Round functie 
Round(2.5) levert bij mij 2 op. Round(2.51) levert wel netjes 3 op.
Ziet iemand hier de logica van?
Round(2.5) levert bij mij 2 op. Round(2.51) levert wel netjes 3 op.
Ziet iemand hier de logica van?
Doet iets met Cloud (MS/IBM)
Die maakt een INT van een FLOAT
Gevonden met GoogleThe native VB6 Round is problematic:
VB6 Round rounds 1/2 to nearest the even number (aka 'Banker's rounding')
Round(1.5) => 2
Round(2.5) => 2 !! should be 3 in 'Other people's rounding'
VB6 Round does *not* support numDecimalPlaces to be negative, eg:
Round(123.45, -1) => 120 !! run-time error 5 in VB6
Digitaal onderwijsmateriaal, leermateriaal voor hbo
Doet iets met Cloud (MS/IBM)
* gorgi_19 blijft copy pasten..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| ... some people think "Banker's rounding" is bad, but it is not the case. This "Banker's" method uses the Gauss rule that if you are in an perfect half case, you must round to the nereast digit that can be divided by 2 (0,2,4,6,8). This rule is important to obtain more accurate results with rounded numbers after operation. Now, an example : 2 digits 2 digits Unrounded "Standard" rounding "Gaussian" rounding 54.1754 54.18 54.18 343.2050 343.21 343.20 +106.2038 +106.20 +106.20 ========= ======= ======= 503.5842 503.59 503.58 Which one is nearer from unrounded result ? The "Gaussian" one (Difference of 0.0042 with "Gaussian/Banker" and 0.0058 with "Standard" rounding.) Another example with half-round cases only: 1 digit 1 digit Unrounded "Standard" Rounding "Gaussian rounding" 27.25 27.3 27.2 27.45 27.5 27.4 + 27.55 + 27.6 + 27.6 ======= ====== ====== 82.25 82.4 82.2 Again, the "Gaussian" rounding result is nearer from the unrounded result than the "Standard" one. |
Digitaal onderwijsmateriaal, leermateriaal voor hbo
Doet iets met Cloud (MS/IBM)
VB6 != VBscript; weet niet of ze hier een andere functie voor hebben geschreven...Kermit schreef op 13 November 2002 @ 10:54:
Dat is stom, check ff m'n zojuist gemaakt ASP pagina:
ASP pagina
Digitaal onderwijsmateriaal, leermateriaal voor hbo
Kermit schreef op 13 november 2002 @ 10:54:
Dat is stom, check ff m'n zojuist gemaakt ASP pagina:
ASP pagina
Doet iets met Cloud (MS/IBM)
Het is allebei ROUND...D2k schreef op 13 November 2002 @ 10:55:
[...]
zet even de acties erbij
het ene is VB round? en het andere?
1
2
3
4
5
6
7
8
9
10
11
| <% afrond1 = Round(1.5) afrond2 = Round(2.5) Response.write("1<B>.</B>5 wordt: " & afrond1 & "<BR>") Response.write("2<B>.</B>5 wordt: " & afrond2 & "<P>") afrond3 = Round(1,5) afrond4 = Round(2,5) Response.write("1<B>,</B>5 wordt: " & afrond3 & "<BR>") Response.write("2<B>,</B>5 wordt: " & afrond4 & "<P>") %> |
Exact expert nodig?
Verwijderd
Zeg nooit nooit: 2.5 kan toevallig wél exact opgeslagen worden, als: (1 + (1/2) ^ 2) * (2 ^ 1). Dit geldt voor alle getallen die (binnen het redelijke) met een eindig aantal machten van 2 genoteerd kunnen worden. De exponenten daarvan moeten wel een beetje dicht bij elkaar liggen, though.Verwijderd schreef op 13 november 2002 @ 20:43:
je moet ook niet vergeten dat floats nooit precies opgeslagen zijn, door de interne binaire representatie ervan
SA007 schreef op 13 november 2002 @ 22:03:
In plaats van de Round functie kun je ook doen
<code>
Int(Getal +0.5)
</code>
Dat doet het wel goed
Doet iets met Cloud (MS/IBM)
Apple iPhone 16e LG OLED evo G5 Google Pixel 10 Samsung Galaxy S25 Star Wars: Outlaws Nintendo Switch 2 Apple AirPods Pro (2e generatie) Sony PlayStation 5 Pro
Tweakers is onderdeel van
DPG Media B.V.
Alle rechten voorbehouden - Auteursrecht © 1998 - 2025
•
Hosting door TrueFullstaq