Article View: be.comp.programming
Article #10412Re: Getallen naar boven afronden
From: Philip Paeps
Date: Sun, 10 Mar 2002 13:09
Date: Sun, 10 Mar 2002 13:09
48 lines
2372 bytes
2372 bytes
Marc DEVLIEGER <Marc.Devlieger@pandora.be> wrote:
> Vrienden,
> Hoe kan ik in VB alle getallen met komma
> altijd naar boven afronden ?
Ik gebruik geen VB, maar in een deftige taal zou ik dit zo doen:
| #include <stdio.h>
| #include <math.h>
|
| double x_orig; /* original double */
| double x_round; /* rounded double */
|
| char cli[128]; /* cli buffer */
|
| int
| main ()
| {
| /* get the number to round */
| printf ("Number > ");
| fgets (cli,128,stdin);
| sscanf (cli, "%lf", &x_orig);
|
| /* round the number using ceil(3) */
| x_round = ceil (x_orig);
|
| /* print the number using 'suitable' precision */
| printf ("%g rounds to %g\n", x_orig, x_round);
| return(0);
| }
Compilen doe je met:
% cc -o round -Wall -pedantic round.c -lm
Nadeel: door %g als format aan printf(3) te geven, zal hij 'grote' getalen in
expontenti�le vorm printen. Je kan %f of %lf gebruiken om dit te vermijden.
Ik veronderstel dat VB ook wel een maths library zal hebben, en dat daar ook
wel een ceil(3) functie in zal zitten. Maar je weet nooit met VB.
- Philip
--
Philip Paeps philip@paeps.cx
Anybody can win - unless there happens to be a second entry.
Technical Details
Message-ID:
<dWIi8.246989$rt4.24047@afrodite.telenet-ops.be>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news-x2.support.nl!newsfeeds.belnet.be!news.belnet.be!ossa.telenet-ops.be!afrodite.telenet-ops.be.POSTED!not-for-mailReferences:
<sIri8.245299$rt4.23941@afrodite.telenet-ops.be>Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII
X-Google-Thread: fcea4,474631146d31b334
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2002-03-10 05:20:42 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news-x2.support.nl!newsfeeds.belnet.be!news.belnet.be!ossa.telenet-ops.be!afrodite.telenet-ops.be.POSTED!not-for-mail
From: Philip Paeps <philip@paeps.cx>
Subject: Re: Getallen naar boven afronden
Newsgroups: be.comp.programming
References: <sIri8.245299$rt4.23941@afrodite.telenet-ops.be>
User-Agent: tin/1.5.12-20020227 ("Toxicity") (UNIX) (FreeBSD/4.5-STABLE (i386))
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
Lines: 48
Message-ID: <dWIi8.246989$rt4.24047@afrodite.telenet-ops.be>
Date: Sun, 10 Mar 2002 13:09:29 GMT
NNTP-Posting-Host: 213.118.35.252
X-Complaints-To: abuse@pandora.be
X-Trace: afrodite.telenet-ops.be 1015765769 213.118.35.252 (Sun, 10 Mar 2002 14:09:29 MET)
NNTP-Posting-Date: Sun, 10 Mar 2002 14:09:29 MET
Organization: Telenet Internet